Shop OBEX P1 Docs P2 Docs Learn Events
Can PINK receive and process HTTP POST requests? — Parallax Forums

Can PINK receive and process HTTP POST requests?

SapphireSapphire Posts: 496
edited 2015-02-02 08:15 in General Discussion
I have a HAN device that sends information via HTTP POST requests, and I'd like to capture and process them with my PINK module so that a Stamp or Prop can read the data variables serially. Does anybody know if this is possible?

I have been able to configure the HAN device to send the HTTP POST request to the IP of the PINK, and it seems happy doing so as it says it successfully connected to the PINK, and the data activity LED on the PINK flashes as each packet is sent (about once every 10 seconds).

But what I don't know how to do is write a script for the PINK to capture the HTTP POST request, strip out the data I want and put it in the serially accessible variables. Any suggestions on how to do this would be appreciated.

Comments

  • SavageCircuitsSavageCircuits Posts: 256
    edited 2015-02-01 15:11
    Yes, it is possible. Somewhere I have a page where you could update variables using the POST method. I haven't used the PINK in a bit but I will see if I can find that HTML file.
  • SapphireSapphire Posts: 496
    edited 2015-02-01 15:59
    Thanks Chris. If you could find that sample HTML file, I would really appreciate it.
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2015-02-01 17:43
    Here's a simple HTML code that lets you enter a value into a field and POST it to the PINK variable specified. I have some more. Still looking...

    [HTML]<html>
    <form method="post" action="test.htm"
    <p>
    What value would you like to store in variable 01?
    <input name="Nb_var01" type="text" maxlength="64">
    <input type="submit" value="Accept">
    </p>
    </form>
    </html>
    [/HTML]

    This file was called, test2.htm and once you post the value it loads test.htm which displays the value (see below).

    [HTML]<html>
    The value in variable 01 is: <Nb_var01>
    </html>
    [/HTML]
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2015-02-01 17:46
    This Multi-Field Form Submit example demonstrates how to
    send/update multiple variables at the same time from a form.
    The downside from the BASIC Stamp side is that the variable
    which shows the Last Update variable will only indicate the
    last one updated before the submit. So in this case it will
    read 03, since variable 03 is the last one being updated.
    There is no way to detect that multiple variables were updated
    using this method without using another register as part of
    the update. For example, you could force another register to
    value when this form is submitted and then check that register
    to determine that multiple values were updated.

    [HTML]<html>
    <body>

    <FORM method="post">
    <P>
    What value would you like stored in these variables?</P>
    <P>
    01 <INPUT name="Nb_var01" type="text" size="75" maxlength="64"></P>
    <P>
    02 <INPUT name="Nb_var02" type="text" size="75" maxlength="64"></P>
    <P>
    03 <INPUT name="Nb_var03" type="text" size="75" maxlength="64"></P>
    <P>
     <INPUT type="submit" value="Send">    
    </P>
    </FORM>
    </html>[/HTML]
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2015-02-01 17:52
    I found one more. Sadly I think I may have misplaced the code to my security system which uses the PINK module. It also uses some javascript stuff. Well, hopefully these examples will help.

    [HTML]<html>
    <body>

    <FORM method="post">
    <P>
    What value would you like stored in these variables?</P>

    00 <INPUT name="Nb_var00" type="text" size="75" maxlength="64"> <br>

    01 <INPUT name="Nb_var01" type="text" size="75" maxlength="64"> <br>

    02 <INPUT name="Nb_var02" type="text" size="75" maxlength="64"> <br>

    03 <INPUT name="Nb_var03" type="text" size="75" maxlength="64"> <br>

    04 <INPUT name="Nb_var04" type="text" size="75" maxlength="64"> <br>

    05 <INPUT name="Nb_var05" type="text" size="75" maxlength="64"> <br>

    06 <INPUT name="Nb_var06" type="text" size="75" maxlength="64"> <br>

    07 <INPUT name="Nb_var07" type="text" size="75" maxlength="64"> <br>

    08 <INPUT name="Nb_var08" type="text" size="75" maxlength="64"> <br>

    09 <INPUT name="Nb_var09" type="text" size="75" maxlength="64"> <br>

    10 <INPUT name="Nb_var10" type="text" size="75" maxlength="64"> <br>

    11 <INPUT name="Nb_var11" type="text" size="75" maxlength="64"> <br>

    12 <INPUT name="Nb_var12" type="text" size="75" maxlength="64"> <br>

    13 <INPUT name="Nb_var13" type="text" size="75" maxlength="64"> <br>

    14 <INPUT name="Nb_var14" type="text" size="75" maxlength="64"> <br>

    15 <INPUT name="Nb_var15" type="text" size="75" maxlength="64"> <br>

    16 <INPUT name="Nb_var16" type="text" size="75" maxlength="64"> <br>

    17 <INPUT name="Nb_var17" type="text" size="75" maxlength="64"> <br>

    18 <INPUT name="Nb_var18" type="text" size="75" maxlength="64"> <br>

    19 <INPUT name="Nb_var19" type="text" size="75" maxlength="64"> <br>

    20 <INPUT name="Nb_var20" type="text" size="75" maxlength="64"> <br>

    <script type="text/javascript">
    var d="<Nb_var00>"
    </script>

    21 <INPUT name="Nb_var21" value=d size="75" maxlength="64"> <br>

    22 <INPUT type=checkbox value="<Nb_var22>"> <br>

    23 <INPUT type="radio" name="Nb_var23"> <br>

    <P>
     <INPUT type="submit" value="Send">    
    </P>
    </FORM>
    </html>[/HTML]
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2015-02-01 17:57
    Oh, I found one more backup file from when I first started using the PINK and actually uploading pages using MS Front Page. Here is an archive of the project. It had some graphics, sounds, etc.
  • SapphireSapphire Posts: 496
    edited 2015-02-01 18:19
    Thanks Chris. I'll take a look at this and see what I can do.
  • SapphireSapphire Posts: 496
    edited 2015-02-01 19:05
    Chris,

    I've looked at your examples to see what they do. It appears they allow a user to enter values into the variables and then post them to the PINK. I ran the example HTM files to test that.

    But in my situation, there will be no browser connected to the PINK, only the HAN web server which is sending HTTP POST requests (sort of like a HTTP GET request with a payload). So I need to capture this incoming HTTP stream, and pick out the data from it (which is in XML fragments as plain text). I don't know much about scripting or HTML, and am not sure where to start. Or if it's even possible to do this with the PINK. Any ideas?
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2015-02-01 19:43
    Well, the PINK uses the POST method to affect variables via the web page interface. However, I have never tested whether or not the code to handle the post request must exist on the web server itself. It would seem that may be the case, however I have never tested the theory. On the other hand many things are initiated from the client (browser) side, so it may be possible to inject the request into the web server with the data. I would imagine it would involve generating the request via port 80 in the same manner that the browser initiates a request on a page. Normally I would say that I would hook one up and test the concept but I will be working in the Rocklin Office (Parallax HQ) in the coming weeks and won't be able to just set something up on my home office bench like I would normally do.

    I would take a look at the way the browser handles the request to post the data when post button is pressed on one of the examples I sent. Then you can try taking the button out of the equation and submitting the request without the source web page.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-02-02 08:15
    Sapphire,

    To elaborate on that, if you look at the way the URL is formed when making certain requests or submitting certain information, you'll notice it often contains the information necessary to process the request/submission. I have used this trick in the past to make automated queries to certain sites, such as IP address lookups. =)
Sign In or Register to comment.