I was wondering if there is a way to access the variables on the PINK module through java script instead of with HTML. Any help would be greatly appreciated.
Yes, you certainly can use Javascript to access variables on the PINK. I did a quick search as I was sure I posted this before but I cannot seem to find it. So what I can do is take a quick look when I get home and post some example code for you. I think in my example the page is waiting for a variable to equal some value at which point it loads a new page.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Engineering
This is always in the head code.· What I did was after the variables are all displayed I have the following javascript code.· What it does is test a variable (in this case Nb_var00) for a specific string.· If this string matches, an alternate page (index2.htm) is loaded.
<script type="text/javascript">
var d="<Nb_var00>"
if (d==="ALERT!")
{
window.location = "index2.htm"
}
</script>
The alternate web page·includes a line to cause a wave file to be played continuously while at the same time·the page is refreshed every 10 seconds to update status.
When I 'acknowledge' the alert by entering information on this page, that variable is also captured and the page is changed again.· If you're wondering this is test code from my home security system which I can monitor from work via the web.· Obviously in order to keep the data updated the page refreshes are necessary.· I don't even have to have the page visible to know if there is an issue because of the wave file, although I did have to go into my sound settings and disable to windows default click sound when a page refreshes as that was driving me nuts.· I hope this code helps out.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Engineering
Thanks for the reply! Is there a way to set them as well? I'm using Dashcode to create an iPhone web app which, the only problem is that Dashcode has me working in a strictly javascript file and I don't know how to edit the Pink's variables in a strictly javascript file.
Setting variables via the web page can only be done using the HTTP POST method as per the documentation. These new variables must be submitted to the web server in that manner. It may be possible to use Javascript to assist in this, however I have not tried to do anything in that manner. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Engineering
Thanks for the reply. I actually figured out how to submit a new variable value using the XMLHTTP request in a Java Script only file.
// Values you provide
var feedURL = "192.168.2.22/"; // The module to update
var onloadHandler = function() { xmlLoaded(xmlRequest); }; // The function to call when the module is loaded; currently calls the XMLHttpRequest load snippet
// XMLHttpRequest setup code
var xmlRequest = new XMLHttpRequest();
xmlRequest.onload = onloadHandler;
xmlRequest.open("post", feedURL);
xmlRequest.setRequestHeader("variable", "");
xmlRequest.send("variable=[noparse][[/noparse]value]")
In the first line the var feedurl is the IP of the pink module. In the second to last line of code you can state which variable you want to change, just enter the variable you want to change in between the first set of quotation marks. As well the last line of code is were you state the value you want the variable to be in this case I wanted Nb_var01 to equal 1, but you can change the variable and the value to what you want it to be, just make sure you keep the formating of ("variable=[noparse][[/noparse]value]"). And the beauty of this is that it is Java Script so you don't have to reload the page to submit it, just have a button call on it.
Comments
Yes, you certainly can use Javascript to access variables on the PINK. I did a quick search as I was sure I posted this before but I cannot seem to find it. So what I can do is take a quick look when I get home and post some example code for you. I think in my example the page is waiting for a variable to equal some value at which point it loads a new page.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
The following code causes the web page (index1.htm) to self-refresh every 5 seconds, causing the variables to be updated every 5 seconds as well.
<head>
<meta http-equiv="refresh" content="5">
<title>Refresh Test</title>
</head>
This is always in the head code.· What I did was after the variables are all displayed I have the following javascript code.· What it does is test a variable (in this case Nb_var00) for a specific string.· If this string matches, an alternate page (index2.htm) is loaded.
<script type="text/javascript">
var d="<Nb_var00>"
if (d==="ALERT!")
{
window.location = "index2.htm"
}
</script>
The alternate web page·includes a line to cause a wave file to be played continuously while at the same time·the page is refreshed every 10 seconds to update status.
<head>
<meta http-equiv="refresh" content="10">
<title>Security</title>
<bgsound src="door.wav" loop="1">
</head>
When I 'acknowledge' the alert by entering information on this page, that variable is also captured and the page is changed again.· If you're wondering this is test code from my home security system which I can monitor from work via the web.· Obviously in order to keep the data updated the page refreshes are necessary.· I don't even have to have the page visible to know if there is an issue because of the wave file, although I did have to go into my sound settings and disable to windows default click sound when a page refreshes as that was driving me nuts.· I hope this code helps out.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Post Edited (Neil B.) : 2/26/2009 12:18:33 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
In the first line the var feedurl is the IP of the pink module. In the second to last line of code you can state which variable you want to change, just enter the variable you want to change in between the first set of quotation marks. As well the last line of code is were you state the value you want the variable to be in this case I wanted Nb_var01 to equal 1, but you can change the variable and the value to what you want it to be, just make sure you keep the formating of ("variable=[noparse][[/noparse]value]"). And the beauty of this is that it is Java Script so you don't have to reload the page to submit it, just have a button call on it.
I’m glad to see you got it figured out. It seems JavaScript has a post function which I haven’t used before. This is good to know. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering