scripting

Plugwise Forum about Plugwise devices and the Source software.

scripting

Postby tktenkate » Sun Jan 26, 2014 5:10 pm

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.
tktenkate
Starting Member
Starting Member
 
Posts: 2
Joined: August 2013

Re: scripting

Postby PietjeNL » Sun Jan 26, 2014 9:23 pm

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.
PietjeNL
Member
Member
 
Posts: 149
Joined: May 2010

Re: scripting

Postby tktenkate » Sun Jan 26, 2014 10:37 pm

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.
tktenkate
Starting Member
Starting Member
 
Posts: 2
Joined: August 2013

Re: scripting

Postby quli420 » Wed Feb 18, 2015 12:55 pm

Same problem here... I reverted back to the nON beta release. Im not using the smile anymore so no need for the beta.!!!!!!!!!!!!!!!!!!!!!!! :o
We offer best quality Certkiller ccnp route pdf test papers and ccie a+ practice 220-801 exam
quli420
Starting Member
Starting Member
 
Posts: 1
Joined: February 2015


Return to Plugwise Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron