Page 1 of 1

scripting

Posted: Sun Jan 26, 2014 6:10 pm
by tktenkate
Hi,

I have the source webserver running and I have a powerfailure script which checks every minute if a plug comes online. If this happens the script turns off some of the scripts. This works perfect.

Now, I want to turn off/on some plugs based on sunrise /sunset times. I found a javascript which calculates these times and put the sunrise and sunset time in a javascript variable. Now it seems impossible for me to get these variables into the plugwise scripting environment.

So, is it possible to assign variables set in javascript to the plugwise scripting environment?

Some examples would help.

Re: scripting

Posted: Sun Jan 26, 2014 10:23 pm
by PietjeNL
In the www folder there is a script called SunRiseSunSet.pte
Dont know what it does, but by the name it should do the job.
Never tryed it myself.

Re: scripting

Posted: Sun Jan 26, 2014 11:37 pm
by tktenkate
In the www folder there is a script called SunRiseSunSet.pte
Yes, I know, I have looked at it. The script basically gets the Sun rise / sun set time from a table from website for given date. It then echos it on the web page.
However, I would prefer not to fetch the sun rise and sun set times from an extern web site. I already have the calculation at hand in a javascript.

I have googled a bit and it seems to be problematic as javascript is executed at the client side and the scripting of plugwise source site is at the server side.
What I did is making an html page with the javascript and call a pte script at the server side. This sort of works.

testsunrise.html:

Code: Select all

<script type='text/javascript'>
/* a lot of lines of code, eventually giving sun_rise and sun_set times
 */

/*call server script and give sun_rise and sun_set as variables
 */
window.location.href = "http://localhost:8089/testsunrise.pte?sun_rise=" + sun_rise + "&sun_set=" + sun_set;

</script>
The server script is loaded and recalls the testsunrise.html page after a number of seconds
testsunrise.pte

Code: Select all

<%
$sun_rise=Request.Get["sun_rise"]
$sun_set= Request.Get["sun_set"]

$t = System.Time;
$d = System.Date;
echo "current date: ", $d, '<br>'
echo "current time: ", $t, '<br>'
echo "sunrise: ", $sun_rise, "sunset: ", $sun_set, '<br>'


if $t>$sun_set
  echo "later than ", $sun_set
/if
%>
<script type='text/javascript'>
setInterval('redirect()',10000)

function redirect()
{
  window.location.href = "http://localhost:8089/testsunrise.html"
}
</script>
So this is basically a working solution. In the server script I can switch on or switch off plugs on basis of an id.
But is this really the way to go or are there other solutions?

Are there any practical scripts and examples out there? I have studied the example source web site which does al kinds of tricks with ajax and javascript but this was too complex for me.

Would love to see what others have done with scripting and would appreciate any pointers.

Re: scripting

Posted: Wed Feb 18, 2015 1:55 pm
by quli420
Same problem here... I reverted back to the nON beta release. Im not using the smile anymore so no need for the beta.!!!!!!!!!!!!!!!!!!!!!!! :o