Shop OBEX P1 Docs P2 Docs Learn Events
PINK Module — Parallax Forums

PINK Module

Neil B.Neil B. Posts: 4
edited 2009-02-27 16:19 in BASIC Stamp
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.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-02-25 18:48
    Neil,

    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-02-25 18:59
    I guess I should look harder before I reply...okay, so here's how the example works...

    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
  • Neil B.Neil B. Posts: 4
    edited 2009-02-26 00:07
    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.

    Post Edited (Neil B.) : 2/26/2009 12:18:33 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-02-26 18:46
    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
  • Neil B.Neil B. Posts: 4
    edited 2009-02-27 02:18
    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-02-27 16:19
    Neil,

    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
Sign In or Register to comment.