Shop OBEX P1 Docs P2 Docs Learn Events
Can I upload from Spinneret to a remote server? — Parallax Forums

Can I upload from Spinneret to a remote server?

MoskogMoskog Posts: 554
edited 2011-07-27 22:11 in Accessories
I bought the PINK some time ago because I thought it could do that because it could be able to send emails.
But it didn't and I had to use the PINK itself to store the web-pages. That means all access to my pages have to go through my own ADSL-modem into the PINK. And thats not a good solution when the internet provider always change IP-address every time resetting or power out. I am currently using no-ip.com but the best for me would be if PINK or perhaps a Spinneret could be able to upload the pages to the remote server I already pay for to my Internet provider.
So., before I buy a Spinneret, can it do that If I put into information on Profile name, Host-name, passwords and all that necessary stuff?
«1

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-03-02 12:10
    Can I upload from Spinneret to a remote server?
    Yes

    You want the device to upload a page to your web site? What protocol, HTTP? If so, It would be easier to write a script on the web server to accept a page upload. Then just POST to that script.
    So., before I buy a Spinneret, can it do that If I put into information on Profile name, Host-name, passwords and all that necessary stuff?

    Sure, if the login is not https:. I don't think anyone has developed SSL code to-date.
  • MoskogMoskog Posts: 554
    edited 2011-03-02 12:51
    Thank you so much, Mike G, thats all I needed to know.
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-14 07:46
    Has anyone found a solution to this problem? Can you get the Spinneret to automatically POST the data to an external server? I can use GET to send the data to the script on the server, but it needs to be opened up in a web browser to send. I need this all to happen automatically with data being inputted into the Spinneret.
  • Mike GMike G Posts: 2,702
    edited 2011-07-14 13:02
    Can you get the Spinneret to automatically POST the data to an external server?
    Yes,
    1) Initialize the W5100 with the remote host IP and port.
    2) Open a socket connection to the server
    3) Create a properly formatted header
    4) Add your POST data to the body of the message
    5) Send the message to the server.
    7) [Server] Process request
    8) Grab the response

    Please see the W5100 manual and the HTTP protocol.
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-17 09:02
    What if the server my website is on cannot be connected to via the IP address? The only IP address I have can be used to connect via FTP.
  • Mike GMike G Posts: 2,702
    edited 2011-07-17 10:21
    @worthyamherst, your web server has to have an IP address. All URLs resolve to an IP. When your browser goes to www. mysite .com, it first resolves the IP address. It uses that IP address to open a socket on the server.

    If what you are saying is correct, then you can not use the Spinneret to connect to your web server.
  • Mike GMike G Posts: 2,702
    edited 2011-07-17 10:47
    Here's the log of my Spinneret hitting your server http://wbuffalo.workforceinnovators.org/index.html. I only grabbed a buffer full of data.
    ----- Start 07/17/2011 17:40:33 -----
    HTTP/1.1 200 OK
    Date: Sun, 17 Jul 2011 17:40:29 GMT
    Server: Apache
    Last-Modified: Tue, 12 Jul 2011 17:40:03 GMT
    Accept-Ranges: bytes
    Content-Length: 5010
    X-Powered-By: PleskLin
    Connection: close
    Content-Type: text/html
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
    <META NAME="Generator" CONTENT="NetObjects Fusion&#65533;Essentials&#65533;(http://www.netobjects.com)">
    <TITLE>Home</TITLE>
    <SCRIPT>
    <!--
    function F_loadRollover(){} function F_roll(){}
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="JavaScript1.2" SRC="./assets/rollover.js"></SCRIPT>
    </HEAD>
    <BODY NOF="(MB=(DefaultMasterBorder, 121, 65, 212, 10), L=(HomeLayout, 1269, 430))" BGCOLOR="#FFFFFF" BACKGROUND="./assets/images/Background.jpg" TEXT="#000000" TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
        <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=1168 NOF=LY>
            <TR VALIGN=TOP ALIGN=LEFT>
                <TD>
                    <TABLE 
    ----- End 07/17/2011 17:40:33 -----
    
    ----- Start 07/17/2011 17:41:18 -----
    HTTP/1.1 200 OK
    Date: Sun, 17 Jul 2011 17:41:14 GMT
    Server: Apache
    Last-Modified: Tue, 12 Jul 2011 17:40:03 GMT
    Accept-Ranges: bytes
    Content-Length: 5010
    X-Powered-By: PleskLin
    Connection: close
    Content-Type: text/html
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
    <META NAME="Generator" CONTENT="NetObjects Fusion&#65533;Essentials&#65533;(http://www.netobjects.com)">
    <TITLE>Home</TITLE>
    <SCRIPT>
    <!--
    function F_loadRollover(){} function F_roll(){}
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="JavaScript1.2" SRC="./assets/rollover.js"></SCRIPT>
    </HEAD>
    <BODY NOF="(MB=(DefaultMasterBorder, 121, 65, 212, 10), L=(HomeLayout, 1269, 430))" BGCOLOR="#FFFFFF" BACKGROUND="./assets/images/Background.jpg" TEXT="#000000" TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
        <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=1168 NOF=LY>
            <TR VALIGN=TOP ALIGN=LEFT>
                <TD>
                    <TABLE 
    ----- End 07/17/2011 17:41:18 -----
    


    This is the code I used. Your web server's IP is 216.177.135,.4 and the Port is 80
    PUB GetWfi(id) | st, size, idx, tempMask
      pst.str(string(13,"Get WFI!",13))
      tempMask := tcpMask
      tcpMask := SetTcpSocketMaskById(id, 0)
    
      Socket.Close(id)
      pause(delay)
      InitializeWfiSocket(id)
      pause(delay)
    
      'Get My IP
      pst.str(string(13, "Getting Assigned IP ",13))
      Socket.Connect(id)
      pause(delay)
      repeat while !Socket.Connected(id)
    
      pst.str(string(13, "Sending Header ",13))
      
      'spinneret/myip.aspx
      'spinneret/datetime.aspx
      '/spinneret/getpost.aspx?id=1&test=2
      StringSend(id, string("GET /index.html HTTP/1.1", 13, 10))
      StringSend(id, string("Keep-Alive: 115", 13, 10))
      StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
      StringSend(id, string("Connection: keep-alive", 13, 10))
      StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
      StringSend(id, string("Content-length: 23", 13, 10, 13, 10))
      StringSend(id, string("name=test&submit=Submit"))
    
      
      repeat until size := Socket.rxTCP(id, @rxdata)
      pst.str(@rxdata)
      AppendLog(@rxdata)
    
      'Find and print the message body
      'idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true)
      'pst.str(@rxdata+idx+4)
    
    
      'Reset the socket
      Socket.Disconnect(id)
      InitializeSocket(id)
      
      'Reset the tcpMask
      tcpMask := tempMask
    

    I don't know why I have to keep saying this... but if you want help post your source code.
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-17 15:56
    The script I'm using is:


    <html><body>
    <?php

    $one = $_GET;
    $two = $_GET;

    echo "Var one: ", $one, " ";
    echo "Var two: ", $two;


    $myFile = "test.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    $StringData = "one: ";
    fwrite($fh, $StringData);
    $StringData = $one;
    fwrite($fh, $StringData);
    $StringData = "\n";
    fwrite($fh, $StringData);
    $StringData = "two: ";
    fwrite($fh, $StringData);
    $StringData = $two;
    fwrite($fh, $StringData);
    $StringData = "\n";
    fwrite($fh, $StringData);
    fclose($fh);

    ?>
    </body></html>

    This script is located at: http://wbuffalo.workforceinnovators.org/test.php
    POST version: http://wbuffalo.workforceinnovators.org/testpst.php

    The file they both write to is located at: http://wbuffalo.workforceinnovators.org/test.txt

    In the final solution, I need to be able to take data given to the Spinneret from a Basic Stamp up to the website.
  • Mike GMike G Posts: 2,702
    edited 2011-07-17 18:35
    Functioned as expected .. results from http://wbuffalo.workforceinnovators.org/test.txt
    one: 
    two: 
    one: 
    two: 
    one: mikeg_test
    two: somestuff
    

    AlI I did was add a QueryString to the end of the requested resource.
    PUB GetWfi(id) | st, size, idx, tempMask
      pst.str(string(13,"Get WFI!",13))
      tempMask := tcpMask
      tcpMask := SetTcpSocketMaskById(id, 0)
    
      Socket.Close(id)
      pause(delay)
      InitializeWfiSocket(id)
      pause(delay)
    
      'Get My IP
      pst.str(string(13, "Getting Assigned IP ",13))
      Socket.Connect(id)
      pause(delay)
      repeat while !Socket.Connected(id)
    
      pst.str(string(13, "Sending Header ",13))
      
      'spinneret/myip.aspx
      'spinneret/datetime.aspx
      '/spinneret/getpost.aspx?id=1&test=2
    
      StringSend(id, string("GET /test.php?1=mikeg_test&2=somestuff HTTP/1.1", 13, 10))
      StringSend(id, string("Keep-Alive: 115", 13, 10))
      StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
      StringSend(id, string("Connection: keep-alive", 13, 10))
      StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
      StringSend(id, string("Content-length: 23", 13, 10, 13, 10))
      StringSend(id, string("name=test&submit=Submit"))
    
      
      repeat until size := Socket.rxTCP(id, @rxdata)
      pst.str(@rxdata)
      AppendLog(@rxdata)
    
      'Find and print the message body
      'idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true)
      'pst.str(@rxdata+idx+4)
    
    
      'Reset the socket
      Socket.Disconnect(id)
      InitializeSocket(id)
      
      'Reset the tcpMask
      tcpMask := tempMask
    
  • Mike GMike G Posts: 2,702
    edited 2011-07-17 18:42
    Your PHP POST handler has a problem. My initial requested open the sockets but timed out waiting for a response.

    Post your code... geez I'm trying to help you man!
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-18 07:47
    The POST version has the same exact code with "GET" changed to "POST"...... And what's the rest of the code you used on the Spinneret side to send the data? I'm not even really sure how it all works....
  • Mike GMike G Posts: 2,702
    edited 2011-07-18 09:02
    I give up :( I can't help if you refuse to post your PHP and SPIN/PASM source.

    http://wbuffalo.workforceinnovators.org/test.php functions as expected and responds to client requests. [Edit:] both GET and POST methods function as expected.

    Mult-Socket code base.
    http://www.agaverobotics.com/spinneret/source/
      StringSend(id, string("POST /testpst.php HTTP/1.1", 13, 10))
      StringSend(id, string("Keep-Alive: 115", 13, 10))
      StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
      StringSend(id, string("Connection: keep-alive", 13, 10))
      StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
      StringSend(id, string("Content-length: 34", 13, 10, 13, 10))
      StringSend(id, string("1=post_test&2=from_mikeg_spinneret"))
    
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-18 17:35
    I'm new to this and confused on all of it. haha. I wasn't even sure what you were asking for... :blank: I've only used sample SPIN codes...and am not even sure how those work. I need the step by step from beginning in how to set this up. Like how the parts of code work together and stuff. I also need variables from the SPIN code to be send along with the GET/POST submissions. I'm sorry for being such a newbie. :tongue: LOL
  • Mike GMike G Posts: 2,702
    edited 2011-07-19 16:36
    @worthyamherst, what happened? I thought you were going to give me a call.
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-19 18:13
    We figured out how it all worked before you replied to our message, and we were so excited that I guess we forgot to call. hahaha :lol: . Now we're having problems getting variables stored in the shared memory to send with the GET. Do you have any insights on how to do that? We were trying to convert the VARs to strings, but failed miserably.... I won't have access to the SPIN code we're working with until tomorrow.But, If you have a demo on how to do this, we could easily integrate it into our code. You really have been So much help! we would have still been stuck on our first problem without your assistance.
  • Mike GMike G Posts: 2,702
    edited 2011-07-19 18:32
    @worthyamherst, Wow I really have a warm fuzzy. VARs to string does not make sense. I'm guessing you want to ASCII encode numbers?

    You know the drill, post your problem code, call when you say you will, be considerate to others...
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-20 06:11
    yes, ASCII encode the numbers.
    PUB GETsoc(id) | st, size, idx, tempMask
    pst.str(string(13,"Get WFI!",13))
    tempMask := tcpMask
    tcpMask := SetTcpSocketMaskById(id, 0)
    
    datatosend := 0
    
    tst1 := 1 
    tst2 := 2 
    
    Socket.Close(id)
    pause(delay)
    InitializeSocket(id)
    pause(delay)
    
    'Get My IP
    pst.str(string(13, "Getting Assigned IP ",13))
    Socket.Connect(id)
    pause(delay)
    
    
    
    repeat while !Socket.Connected(id)
    
    pst.str(string(13, "Sending Header ",13))
    
    
    'StringSend(id, string("GET /test.php?1=", tst1, "&2=", tst2, " HTTP/1.1" , 13, 10))
    StringSend(id, string("GET /test.php?1="))
    str.ToString(tst1, @datatosend)
    Stringsend(id, datatosend)
    StringSend(id, string("&2="))
    Stringsend(id, str.ToString(tst2, @datatosend))
    StringSend(id, string(" HTTP/1.1", 10, 13)) 
    StringSend(id, string("Keep-Alive: 115", 13, 10))
    StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
    StringSend(id, string("Connection: keep-alive", 13, 10))
    StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
    StringSend(id, string("Content-length: 23", 13, 10, 13, 10))
    StringSend(id, string("name=test&submit=Submit"))
    
    
    'repeat until size := Socket.rxTCP(id, @rxdata)
    'pst.str(@txdata)
    'AppendLog(@rxdata)
    
    'Find and print the message body
    'idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true)
    'pst.str(@rxdata+idx+4) 
    
    'Reset the socket
    Socket.Disconnect(id)
    Pause(500)
    
    'Reset the tcpMask
    tcpMask := tempMask
    


    we were using the StringMethods object, but it wasn't working out very well.
  • Mike GMike G Posts: 2,702
    edited 2011-07-20 06:15
    Use the ToString method of the StringMethods object.

    @number is a pointer to the input number
    @tempNum is the destination pointer. Where the ASCII string is written
    OBJ
      str           : "StringMethods" 
    ...
     str.ToString(@number, @tempNum)
    

    See the StringMethods object for more information.
  • Mike GMike G Posts: 2,702
    edited 2011-07-20 06:20
    we were using the StringMethods object, but it wasn't working out very well.

    Am I missing something? I'm not seeing your attempt to use the StringMethods in your posted code. If that's your question, how to use StringMethods, then post the problematic code.
  • Mike GMike G Posts: 2,702
    edited 2011-07-20 06:30
    CON
      _clkmode = xtal1 + pll16x     
      _xinfreq = 5_000_000
    
    DAT
      tempNum  byte   $0[10]
    
    OBJ
      str           : "StringMethods"
      pst           : "Parallax Serial Terminal"
    
    PUB Main  | num
    
      str.Start
      pst.Start(115_200)
      pause(1000)
      
      num := 100
      str.ToString(@num, @tempNum)
    
      pst.str(@tempNum)
    
    
    PRI Pause(Duration)  
      waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt)
      return
    
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-20 06:32
    why isn't this working?
    StringSend(id, string("GET /test.php?1="))
      str.ToString(@tst1, @datatosend)
      Stringsend(id, datatosend)
      StringSend(id, string("&2="))
      str.ToString(@tst2, @datatosend)
      Stringsend(id, datatosend)
      StringSend(id, string(" HTTP/1.1", 10, 13))    
      StringSend(id, string("Keep-Alive: 115", 13, 10))
      StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
      StringSend(id, string("Connection: keep-alive", 13, 10))
      StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
      StringSend(id, string("Content-length: 23", 13, 10, 13, 10))
      StringSend(id, string("name=test&submit=Submit"))
    
  • Mike GMike G Posts: 2,702
    edited 2011-07-20 06:53
    Use @datatosend, StringSend expects a pointer.
    Stringsend(id, @datatosend)
    

    It's much easier to answer your question when you post the problem code.
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-20 07:13
    We copied what you did exactly, and it still doesn't work...

    It's sending "51323" to our server for both variables.
    PUB GETsoc(id) | st, size, idx, tempMask
      pst.str(string(13,"Setting Mask",13))
      tempMask := tcpMask
      tcpMask := SetTcpSocketMaskById(id, 0)
         
      str.Start
    
      tst1 := 123 
      tst2 := 456
    
      str.ToString(@tst1, @datatosend1)
      str.ToString(@tst2, @datatosend2)
    
      pst.str(@datatosend1)
      pst.str(@datatosend2) 
               
      Socket.Close(id)
      pause(delay)
      InitializeSocket(id)
      pause(delay)
    
      'Get My IP
      pst.str(string(13, "Connecting",13))
      Socket.Connect(id)
      pause(delay)
      
      repeat while !Socket.Connected(id)
    
      pst.str(string(13, "Sending Header",13))
                       
    
      'StringSend(id, string("GET /test.php?1=", "test1", "&2=", "test2", " HTTP/1.1" , 13, 10))
      StringSend(id, string("GET /test.php?1="))
      'str.ToString(@tst1, @datatosend)
      'pst.str(@datatosend)
      Stringsend(id, @datatosend1)
      StringSend(id, string("&2="))
      'str.ToString(@tst2, @datatosend)
      'pst.str(@datatosend)
      Stringsend(id, @datatosend2)
      StringSend(id, string(" HTTP/1.1", 10, 13))    
      StringSend(id, string("Keep-Alive: 115", 13, 10))
      StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
      StringSend(id, string("Connection: keep-alive", 13, 10))
      StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
      StringSend(id, string("Content-length: 23", 13, 10, 13, 10))
      StringSend(id, string("name=test&submit=Submit"))
    
       
      'repeat until size := Socket.rxTCP(id, @rxdata)
      'pst.str(@txdata)
      'AppendLog(@rxdata)
                
      'Find and print the message body
      'idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true)
      'pst.str(@rxdata+idx+4) 
    
      'Reset the socket
      Socket.Disconnect(id)
      Pause(delay)
      
      'Reset the tcpMask
      tcpMask := tempMask
    
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-20 07:42
    We got that working....but now it's just randomly stopping sending the data.
    CON
      _clkmode = xtal1 + pll16x     
      _xinfreq = 5_000_000
    
      MAX_PACKET_SIZE = 2032
      BUFFER_2K       = $800
      UPD_BUFFER      = $600
      TCP_PROTOCOL    = %0001
      UDP_PROTOCOL    = %0010
      TCP_CONNECT     = $04    
      DELAY           = $05
      
    DAT
      mac                   byte    $00, $1A, $A0, $B4, $58, $5B
      subnet                byte    255, 255 ,255, 0
      ip                    byte    128, 205, 23, 178
      gateway               byte    128, 205, 23, 254
      port                  word    80
      uport                 word    5050
      remoteIp              byte    216, 177, 135, 4
      remotePort            word    80
      emailIp               byte    0, 0, 0, 0
      emailPort             word    25
      status                byte    $00, $00, $00, $00   
      rxdata                byte    $0[BUFFER_2K]
      txdata                byte    $0[BUFFER_2K]
      udpdata               byte    $0[UPD_BUFFER]
      fileErrorHandle       long    $0
      debug                 byte    $0
      lastFile              byte    $0[12], 0
      closedState           byte    %0000
      openState             byte    %0000
      listenState           byte    %0000
      establishedState      byte    %0000
      closingState          byte    %0000
      closeWaitState        byte    %0000 
      lastEstblState        byte    %0000
      lastEstblStateDebug   byte    %0000
      udpListen             byte    %0000
      tcpMask               byte    %0111
      udpMask               byte    %1000   
      fifoSocketDepth       byte    $0
      fifoSocket            long    $00_00_00_00
      debugSemId            byte    $00
      debugCounter          long    $00
      stringMethods         long    $00
      closingTimeout        long    $00, $00, $00, $00
      udpLen                long    $00
      time                  byte    "00/00/0000 00:00:00", 0
      httpDate              byte    "Wed, 01 Feb 2000 01:00:00 GMT", 0
      globalCache           byte    0
      datatosend1           byte   $0[10]
      datatosend2           byte   $0[10]
      
    VAR
      long StackSpace[20]
      long tst1
      long tst2
      
    
    OBJ
      Socket        : "W5100_Indirect_Driver"
      pst           : "Parallax Serial Terminal.spin"
      SDCard        : "SD2.0_FATWrapper"
      Request       : "Request"
      Response      : "Response"
      str           : "StringMethods"
      rtc           : "S35390A_RTCEngine.spin" 
      
    
    PUB Initialize | id, size, st
               
      debug := 1    
      SDCard.Start
      stringMethods := str.Start
      Request.Constructor(stringMethods)
      Response.Constructor(stringMethods, @txdata) 
    
      pst.Start(115_200)
      pause(200) 
             {   
      'Mount the SD card
      pst.str(string("Mount SD Card - ")) 
      SDCard.mount(fileErrorHandle)
      pst.str(string("OK",13))
              }
      pst.str(string("Start RTC: "))
      rtc.RTCEngineStart(29, 28, -1)
      
      pause(200)
      'pst.str(FillTime)
                  
      'Start the W5100 driver
      if(Socket.Start)
        pst.str(string(13, "W5100 Driver Started", 13))
        pst.str(string(13, "Status Memory Lock ID    : "))
        pst.dec(Socket.GetLockId)
        pst.char(13) 
    
    
      if(debugSemId := locknew) == -1
        pst.str(string("Error, no HTTP server locks available", 13))
      else
        pst.str(string("HTTP Server Lock ID      : "))
        pst.dec(debugSemId)
        pst.char(13)
        
    
      'Set the Socket addresses  
      SetMac(@mac)
      SetGateway(@gateway)
      SetSubnet(@subnet)
      SetIP(@ip)
    
      ' Initailize TCP sockets (defalut setting; TCP, Port, remote ip and remote port)
      repeat id from 0 to 3
        InitializeSocket(id)
        Request.Release(id)
        pause(50)
            { 
      ' Set all TCP sockets to listen
      pst.char(13) 
      repeat id from 0 to 3 
        Socket.Listen(id)
        pst.str(string("TCP Socket Listener ID   : "))
        pst.dec(id)
        pst.char(13)
        pause(50)
    
      ' Initialize UDP socket(s)
      
      id := 3
      InitializeUPDSocket(id)
      pause(50)
      pst.str(string("UDP Socket Listener ID   : "))
      pst.dec(id)
      pst.char(13)
      } 
      pst.Str(string(13,"Started Socket Monitoring Service", 13))
     
      cognew(StatusMonitor, @StackSpace)
      pause(250)
    
    
      pst.Str(string(13, "Initial Socket States",13))
      StackDump
    
      pst.Str(string(13, "Initial Socket Queue",13))
      QueueDump
    
             
    
      main
      
    
    PUB Main | packetSize, id, i, reset, j, temp
    
      'HTTP server service
      'GetMyIp(0)
      'SendTestEmail(0)
         {
      pst.str(string(13,"//////////////////////////////////////////////////////////////",13))
      repeat
      
        if(udpMask > 0)
          'Let's see if we have some UDP data
          'when we're not servicing TCP
          udpLen := socket.rxUDP(3, @udpdata)
          if(udpLen > 0)
            pst.str(string(13,"--- UDP --------------------------"))
            pst.str(string(13,"received "))
            pst.dec(udpLen)
            pst.str(string(" bytes from IP "))
            pst.dec(udpdata[0])
            pst.char(".")
            pst.dec(udpdata[1])
            pst.char(".")
            pst.dec(udpdata[2])
            pst.char(".")
            pst.dec(udpdata[3])
            pst.char(":")
            temp := (udpdata[4] * 256) + udpdata[5]
            pst.dec(temp)
            temp := (udpdata[6] * 256) + udpdata[7]
            pst.str(string(" Length = "))
            pst.dec(temp)
            pst.char(13)
            pst.str(@udpdata[8])
            pst.str(string(13,"----------------------------------", 13))
            { 
            udpdata[0] := 192
            udpdata[1] := 168
            udpdata[2] := 1
            udpdata[3] := 120
            udpdata[4] := $13
            udpdata[5] := $88
            
            udpdata[6] := 0
            udpdata[7] := 4
            
            udpdata[8] := "T"
            udpdata[9] := "E"
            udpdata[10] := "S"
            udpdata[11] := "T"
            udpdata[12] := 0
            }
            socket.txUDP(3, @udpdata)
            bytefill(@udpdata, 0, udpLen)
            udpLen := 0
        }   {
        repeat until fifoSocket == 0
        
          bytefill(@rxdata, 0, BUFFER_2K)
    
          if(debug)
            pst.str(string(13, "----- Start of Request----------------------------",13))
            'QueueDump
          else
            pause(DELAY)
            
          ' Pop the next socket handle 
          id := DequeueSocket
          if(id < 0)
            next
          
          if(debug)
            pst.str(string(13,"ID: "))
            pst.dec(id)
            pst.str(string(13, "Request Count     : "))
            pst.dec(debugCounter)
            pst.char(13)
            'StackDump
    
          packetSize := Socket.rxTCP(id, @rxdata)
    
          'if(debug)
            'pst.str(string(13, "packetSize        : "))
            'pst.dec(packetSize)
            'pst.str(string(13, "strsize(@rxdata)  : "))
            'pst.dec(strsize(@rxdata))
            
          'else
            'pause(DELAY)
     
          reset := false
          if ((packetSize < 12) AND (strsize(@rxdata) < 12))
            repeat i from 0 to 5
              'Wait for a few moments and try again
              waitcnt((clkfreq/500) + cnt)
              packetSize := Socket.rxTCP(id, @rxdata)
              if(debug)
                 pst.str(string("retry["))
                 pst.dec(i)
                 pst.str(string("]: "))
                 pst.dec(packetSize)
                 pst.char(13)
              if(packetSize > 12)
                quit
              if(i == 5)
                'Clean up resource request   
                Request.Release(id)
                Socket.Close(id)
                reset := true
                if(debug)
                  pst.str(string(13,"* Read Failure *",13))
                
          if(reset)  
            next
    
          Request.InitializeRequest(id, @rxdata)
          
          {
          if(debug)
            pst.str(string("Content-Length    : "))
            pst.dec(Request.GetContentLength(id))
            pst.char(13)
          }
          {
          if(debug)
            pst.str(string("QueryString: "))
            pst.str(Request.GetQueryString(id))
            pst.char(13)
          }
          
          if(debug)
            pst.char(13)
            HeaderLine1(id)
            'toString(id)
          else
            pause(DELAY)
    
          ' Process router
          Dispatcher(id)
    
    
          'Clean up request resource
          Request.Release(id)
          
            
          ' This starts the close process -> 0x00
          ' use close to force a close
          Socket.Disconnect(id)
          
    
          bytefill(@txdata, 0, BUFFER_2K)
    
    
          if(debug)
            'StackDump
            'pst.char(13)
            'QueueDump
          else
            pause(DELAY)
    
          debugCounter++
            }
    
            GETsoc(0) 
      GotoMain
           
    PUB GETsoc(id) | st, size, idx, tempMask
      pst.str(string(13,"Setting Mask",13))
      tempMask := tcpMask
      tcpMask := SetTcpSocketMaskById(id, 0)
            
      str.Start
    
      tst1 := 123 
      tst2 := 456
    
      str.ToString(@tst1, @datatosend1)
      str.ToString(@tst2, @datatosend2)
    
      pst.str(@datatosend1)
      pst.str(@datatosend2)
       
      Socket.Close(id)
      pause(delay)
      InitializeSocket(id)
      pause(delay)
    
      'Get My IP
      pst.str(string(13, "Connecting",13))
      Socket.Connect(id)
      pause(delay)
      
      repeat while !Socket.Connected(id)
    
      pst.str(string(13, "Sending Header",13))
    
      'StringSend(id, string("GET /test.php?1=", "test1", "&2=", "test2", " HTTP/1.1" , 13, 10))
      StringSend(id, string("GET /test.php?1="))
      Stringsend(id, @datatosend1)
      StringSend(id, string("&2="))
      Stringsend(id, @datatosend2)
      StringSend(id, string(" HTTP/1.1", 10, 13))    
      StringSend(id, string("Keep-Alive: 115", 13, 10))
      StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
      StringSend(id, string("Connection: keep-alive", 13, 10))
      StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
      StringSend(id, string("Content-length: 23", 13, 10, 13, 10))
      StringSend(id, string("name=test&submit=Submit"))
    
       
      'repeat until size := Socket.rxTCP(id, @rxdata)
      'pst.str(@txdata)
      'AppendLog(@rxdata)
                
      'Find and print the message body
      'idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true)
      'pst.str(@rxdata+idx+4) 
    
      'Reset the socket
      Socket.Disconnect(id)
      Pause(delay)
      
      'Reset the tcpMask
      tcpMask := tempMask
    
      
    PRI GotoMain
      Main
      
    PRI QueueDump
      pst.str(string("FIFO["))
      pst.dec(fifoSocketDepth)
      pst.str(string("] "))
      pst.hex(fifoSocket, 8)
    
        
    PRI StackDump | clsd, open, lstn, estb, clwt, clng, id, ulst
    
      repeat until not lockset(debugSemId)
      clsd := closedState
      open := openState
      lstn := listenState
      estb := establishedState
      clwt := closeWaitState
      clng := closingState
      ulst := udpListen
      lockclr(debugSemId)
    
      pst.char(13) 
      repeat id from 3 to 0
        pst.dec(id)
        pst.str(string("-"))
        pst.hex(status[id], 2)
        pst.str(string(" "))
        pause(1)
    
      pst.str(string(13,"clsd open lstn estb clwt clng udps", 13))
      pst.bin(clsd, 4)
      pst.str(string("-"))
      pst.bin(open, 4)
      pst.str(string("-"))
      pst.bin(lstn, 4)
      pst.str(string("-"))  
      pst.bin(estb, 4)
      pst.str(string("-"))  
      pst.bin(clwt, 4)
      pst.str(string("-"))  
      pst.bin(clng, 4)
      pst.str(string("-"))  
      pst.bin(ulst, 4)
      pst.char(13) 
    
    
    PRI StatusMonitor | id, tmp, value
      repeat
    
        Socket.GetStatus32(@status[0])
    
        ' Encode status register states
        repeat until not lockset(debugSemId)
    
        closedState := openState := listenState := establishedState := {
         } closeWaitState := closingState := 0
         
        repeat id from 0 to 3
          case(status[id])
            $00: closedState               |= |< id
                 closedState               &= tcpMask  
            $13: openState                 |= |< id
                 openState                 &= tcpMask                   
            $14: listenState               |= |< id
                 listenState               &= tcpMask
            $17: establishedState          |= |< id
                 establishedState          &= tcpMask
            $18,$1A,$1B: closingState      |= |< id
                         closingState      &= tcpMask
            $1C: closeWaitState            |= |< id
                 closeWaitState            &= tcpMask
            $1D: closingState              |= |< id
                 closingState              &= tcpMask
            $22: udpListen                 |= |< id
                 udpListen                 &= udpMask 
    
        if(lastEstblState <> establishedState)
          value := establishedState
          repeat while value > 0
            tmp := DecodeId(value)
            if(tmp > -1)
              QueueSocket(tmp)
              tmp := |< tmp
              tmp := !tmp
              value &= tmp
          lastEstblState := establishedState
    
        lockclr(debugSemId)
        
        ' Initialize a closed socket 
        if(closedState > 0)
          id := DecodeId(closedState)
          if(id > -1)
            InitializeSocket(id & tcpMask)
        
        'Start a listener on an initialized/open socket   
        if(openState > 0)
          id := DecodeId(openState)
          if(id > -1)
            Socket.Listen(id & tcpMask)
    
        ' Close the socket if the status is close/wait
        ' response processor should close the socket with disconnect
        ' there could be a timeout so we have a forced close.
        ' TODO: CCheck for a port that gets stuck in a closing state
        'if(closeWaitState > 0)
          'id := DecodeId(closeWaitState)
          'if(id > -1)
            'Socket.Close(id & tcpMask)
    
    
    
        'pause(100)
    return
    
    PRI GetTcpSocketMask(id)
      return id & tcpMask
    
    PRI DecodeId(value) | tmp
        if(%0001 & value)
          return 0
        if(%0010 & value)
          return 1
        if(%0100 & value)
          return 2 
        if(%1000 & value)
          return 3
      return -1
    
    
    
    PRI QueueSocket(id) | tmp
      if(fifoSocketDepth > 4)
        return false
    
      tmp := |< id
      
      'Unique check
      ifnot(IsUnique(tmp))
        return false
        
      tmp <<= (fifoSocketDepth++) * 8
      
      fifoSocket |= tmp
    
      return true
    
    
    PRI IsUnique(encodedId) | tmp
      tmp := encodedId & $0F
      repeat 4
        if(encodedId & fifoSocket)
          return false
        encodedId <<= 8
      return true 
        
    
    PRI DequeueSocket | tmp
      if(fifoSocketDepth == 0)
        return -2
      repeat until not lockset(debugSemId) 
      tmp := fifoSocket & $0F
      fifoSocket >>= 8  
      fifoSocketDepth--
      lockclr(debugSemId)
      return DecodeId(tmp)
    
      
    PRI ResetSocket(id)
      Socket.Disconnect(id)
      Socket.Close(id)
    
     
    PRI ChangeDirectory(id) | i
      'Handle directory structure for this Request
      if(Request.GetDepth(id) > 1)
        repeat i from 0 to Request.GetDepth(id)-1
          if(FileExists(Request.GetPathNode(id, i)))
            SDCard.changeDirectory(Request.GetPathNode(id, i))
            return true
          else
            return false
            
      return true
    
    
      
    PRI FileExists(fileToCompare) | filenamePtr
    'Start file find at the top of the list
      SDCard.startFindFile 
      'Verify that the file exists
      filenamePtr := SDCard.nextFile
      repeat while filenamePtr <> 0
        filenamePtr := SDCard.nextFile    
        if(str.MatchPattern(filenamePtr, fileToCompare, 0, false ) == 0 )
          return true
    
      return false
      
    
    
    PRI StaticFileHandler(id) | fileSize, i, headerLen, temp, j
      'pst.str(string(13,"Static File Handler",13)) 
      SDCard.changeDirectory(@approot)
      'pst.char(13)
      
      'Make sure the directory exists
      ifnot(ChangeDirectory(id))
        'send 404 error
        WriteError(id)
        SDCard.changeDirectory(@approot)
        return
        
      ' Make sure the file exists
      ifnot(FileExists(Request.GetFileName(id)))
        'send 404 error
        WriteError(id)
        SDCard.changeDirectory(@approot)
        return
       
      
      
      ' Open the file for reading
      SDCard.openFile(Request.GetFileName(id), "r")
      fileSize := SDCard.getFileSize
    
      'WriteResponseHeader(id)
      'BuildHeader(extension, statusCode, expirer)
      headerLen := Response.BuildHeader(Request.GetExtension(id), 200, false)
      Socket.txTCP(id, @txdata, headerLen)
      
      if fileSize < MAX_PACKET_SIZE
        ' send the file in one packet
        SDCard.readFromFile(@txdata, fileSize)
        Socket.txTCP(id, @txdata, fileSize)
      else
        ' send the file in a bunch of packets 
        repeat
          SDCard.readFromFile(@txdata, MAX_PACKET_SIZE)  
          Socket.txTCP(id, @txdata, MAX_PACKET_SIZE)
          fileSize -= MAX_PACKET_SIZE
          ' once the remaining fileSize is less then the max packet size, just send that remaining bit and quit the loop
          if fileSize < MAX_PACKET_SIZE and fileSize > 0
            SDCard.readFromFile(@txdata, fileSize)
            Socket.txTCP(id, @txdata, fileSize)
            quit
       
          ' Bailout
          if(i++ > 1_000_000)
            WriteError(id)
            quit
         
      SDCard.closeFile
      SDCard.changeDirectory(@approot)
      return
      
    PUB WriteError(id) | headerOffset
    
      pst.str(string(13, "Write 404 Error",13 ))
      headerOffset := Response.BuildHeader(Request.GetExtension(id), 404, false)
      Socket.txTCP(id, @txdata, headerOffset)
      return
    
      
    PUB SetTcpSocketMaskById(id, state) | tmp
      tmp := |< id
      
      if(state == 1)
        tcpMask |= tmp
      else
        tmp := !tmp
        tcpMask &= tmp
    
    
    PUB IsolateTcpSocketById(id) | tmp
      tmp := |< id
      tcpMask &= tmp
    
    PUB GetCommandRegisterAddress(id)
      return Socket#_S0_CR + (id * $0100)
    
    PUB GetStatusRegisterAddress(id)
      return Socket#_S0_SR + (id * $0100)
    
        
    PRI SetMac(_firstOctet)
      Socket.WriteMACaddress(true, _firstOctet)
      return 
    
    
    PRI SetGateway(_firstOctet)
      Socket.WriteGatewayAddress(true, _firstOctet)
      return 
    
    
    PRI SetSubnet(_firstOctet)
      Socket.WriteSubnetMask(true, _firstOctet)
      return 
    
    
    PRI SetIP(_firstOctet)
      Socket.WriteIPAddress(true, _firstOctet)
      return 
    
    
    
    PRI StringSend(id, _dataPtr)
      Socket.txTCP(id, _dataPtr, strsize(_dataPtr))
      return 
    
    
    PRI SendChar(id, _dataPtr)
      Socket.txTCP(id, _dataPtr, 1)
      return 
    
     
    PRI SendChars(id, _dataPtr, _length)
      Socket.txTCP(id, _dataPtr, _length)
      return 
    
    
    PRI InitializeSocket(id)
      Socket.Initialize(id, TCP_PROTOCOL, port, remotePort, @remoteIp)
      return
    
    PRI InitializeSocketForEmail(id)
      Socket.Initialize(id, TCP_PROTOCOL, port, emailPort, @emailIp)
      return
      
    PRI InitializeUPDSocket(id)
      Socket.Initialize(id, UDP_PROTOCOL, uport, remotePort, @remoteIp)
      return 
      
    
    
    PRI HeaderLine1(id) | i
      pst.str(Request.GetMethod(id))
      pst.char($20)
    
      i := 0
      repeat Request.GetDepth(id)
        pst.char($2F)
        pst.str(Request.GetPathNode(id, i++))
    
    '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    'Chance to do some processing before sending the response
    
    PRI Dispatcher(id)
    {    }  
      if(strcomp(Request.GetName(id), string("index")))
        Index(id)
      if(strcomp(Request.GetName(id), string("post")))
        Post(id)
      if(strcomp(Request.GetName(id), string("upload")))
        Upload(id)
      if(strcomp(Request.GetName(id), string("ajax")))
        Ajax(id)
      if(strcomp(Request.GetName(id), string("getdir")))
        GetDir(id)
        return
      if(strcomp(Request.GetName(id), string("gettime")))
        GetTime(id)
        return
      if(strcomp(Request.GetName(id), string("firmware")))
        Firmware(id)
        return
    
        
      StaticFileHandler(id)
      return
    
     {    } 
    PRI Index(id)
      pst.str(string(13, "Index Processor", 13))
      pst.str(string("led := "))
      pst.str(Request.Get(id, string("led")))
      pst.char(13)
      pst.str(string("this := "))
      pst.str(Request.Get(id, string("this")))
      pst.char(13)
      return
    
    {    } 
    PRI Post(id)  
      pst.str(string(13, "**************************", 13))
      pst.str(@rxdata)
      pst.str(string(13, "**************************", 13))
      return
    
    {
       'tempMask := tcpMask
      'IsolateTcpSocketById(id)
     } 
    PRI Upload(id) | tempMask, strt, end, rxBytes, bodyPtr, bytesRead, i, packetSize, j, dataS, dataE, bodySize, bodyE, temp
    
      AppendLog(@rxdata)
      bytefill(@boundary1, 0, 64)
      
      i := 0
      j := 0
      dataE := 0
      bytesRead := 0
      
      ifnot(strcomp(Request.GetMethod(id), String("POST")))
        return
    
      'pst.str(string(13, "Content Length: ")) 
      rxBytes := Request.GetContentLength(id)
      'pst.dec(rxBytes)
      'pst.char(13)
    
      'pst.str(string(13, "@rxdata Length: ")) 
      'pst.dec(strsize(@rxdata))
      'pst.char(13)
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Content-Type: multipart/form-data; boundary=
      'Get the mutlipart boundary
      'pst.str(string(13, "Get start of boundary= "))
      strt := str.MatchPattern(@rxdata, @multipart, 0, false)
      strt += strsize(@multipart)
      'pst.hex(strt, 4)
      'pst.str(string(13, "End of boundary= ") )
      end := str.MatchPattern(@rxdata, @crlf, strt, true)
      'pst.hex(end, 4)
      'pst.str(string(13, "Buffer boundary") )
      bytemove(@boundary1, @rxdata+strt, end-strt)
      'pst.str(string(13, "Boundary: "))
      'pst.str(@boundary)
      'pst.str(string(13, "Boundary Len: "))
      'pst.dec(strsize(@boundary))
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Find the body and see if we need to grab more stream data
      'pst.str(string(13, "Find body data: "))
      strt := str.MatchPattern(@rxdata, @crlf_crlf, 0, true)
      bodyPtr :=  strt + strsize(@crlf_crlf)
      'pst.hex(bodyPtr, 4)
      'pst.str(string(13, "Body length: ")) 
      bodySize := strsize(@rxdata)-bodyPtr
      'pst.dec(bodySize)
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Get the filename being uploaded
      'pst.str(string(13, "Find the start of filename"))
      'Find filename="upload.txt"
      strt := str.MatchPattern(@rxdata, @fn, strt, false)
        if(strt == -1)
          'pst.str(string(13, "Filename not found!"))
          'Try to handle MAC POST
          pause(200)
          packetSize := Socket.rxTCP(id, @rxdata)
          strt := str.MatchPattern(@rxdata, @fn, strt, false)
          if(strt == -1)
            return
    
          
      'pst.str(string(13,"filename pointer: "))
      'pst.hex(strt, 4) 
      'Point to the first letter after the double quote
      strt += strsize(@fn) + 1
      'pst.str(string(13, "Find the end of filename"))
      'Find the ending double quote = $22
      end := str.MatchPattern(@rxdata, @doublequote, strt, true)
      'pst.str(string(13,"End filename pointer: "))
      pst.hex(end, 4)
      if(end-strt > 12)
         'pst.str(string(13, "File name is longer than 12 chars"))
        return
        
      'pst.str(string(13, "Write file name to buffer"))  
      Set(@uploadfile, strt+@rxdata, end-strt)
    
      'pst.str(string(13, "filename: "))
      'pst.str(@uploadfile)
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Drill into the first boundary to get the file content
      '@crlf_crlf should be after the file name in the header
      'pst.str(string(13, "Find file data start: "))
      strt := str.MatchPattern(@rxdata, @crlf_crlf, end, true)
      if(strt == -1)
        strt := 0
      else
        strt :=  strt + strsize(@crlf_crlf)
     
      dataS := strt
      bytesRead := strsize(@rxdata)-dataS
      'pst.hex(dataS, 4)
    
      ' Check for an end boundary
      end :=  str.MatchPattern(@rxdata, @boundary, strt, true)
      'pst.str(string(13, "Find file data end: "))
      'pst.hex(end, 4)
      if(end == -1)
        dataE := 0
      else
        dataE := end-1
        bytesRead := end-strt
      
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
      'write file content to the SD card
      'does the file exist? Yes = delete/create; no = create
      'pst.str(string(13, "change directory"))
      SDCard.changeDirectory(@approot) 
      SDCard.changeDirectory(@uploadfolder)
       
      'pst.str(string(13, "File Exists?"))
      if(FileExists(@uploadfile))
        'pst.str(string(13, "YES File Exists - DELETE"))
        SDCard.deleteEntry(@uploadfile)
    
      'pst.str(string(13, "Create file"))
      SDCard.newFile(@uploadfile)
       
      'pst.str(string(13, "Open file"))
      SDCard.openFile(@uploadfile, "w")
    
      'do we a boundary in the 2K buffer?
      if(end > -1)
        dataE := end
    
      ' Write data within boundaries if everything fits in the buffer
      ' the loop spans the 2k buffer 
      'pst.str(string(13, "Write to file"))
      if(bytesRead > 0)
        SDCard.writeData(@rxdata+dataS, bytesRead)
    
      rxBytes := rxBytes - bodySize
          
     ' pst.str(string(13, "Bytes Left: "))
      pst.dec(rxBytes)
      
      'pst.str(string(13, "Looping"))
      bytefill(@rxdata, 0, BUFFER_2K)     
      repeat while rxBytes > 0
        packetSize := Socket.rxTCP(id, @rxdata)
        if(packetSize > 0)
          'For the most part, I'm see 1460 byte packets in FF
          'Let's see if we hit a boundary
          'and hope the boundary is not split between packets
          end :=  str.MatchPattern(@rxdata, @boundary, 0, true)
          if(end == -1)
            SDCard.writeData(@rxdata, packetSize)
          else
            'pst.str(string(13, "Writing end of data"))
            pst.str(@rxdata+end-2)
            SDCard.writeData(@rxdata, end-2)
    
          rxBytes := rxBytes - packetSize
          'pst.str(string(13, "Bytes Left: "))
          pst.dec(rxBytes)
          pause(200)
          i := 0
        else
          i++
          pause(200) 
        if(i > 100)
          quit    
    
    
      'pst.str(string(13, "loops      : "))
      pst.dec(j)
      'pst.str(string(13, "rxBytes : "))
      pst.dec(rxBytes)
      
      'pst.str(string(13, "Close file", 13))
      SDCard.closeFile
      
      SDCard.changeDirectory(@approot)
    
      
      'Reset the tcpMask
      'tcpMask := tempMask
    
      bytefill(@uploadfile, 0, 12)
      bytefill(@rxdata, 0, BUFFER_2K)
      return
    
    {   }
    
    
    PRI Firmware(id) | strt, end, rxBytes, bodyPtr, bytesRead, i, packetSize, j, dataS, dataE, bodySize, bodyE, temp
    
      packetSize := 0
      
      ifnot(strcomp(Request.GetMethod(id), String("PUT")))
        return
    
      pst.char(13)
      pst.char(13)  
      pst.str(@rxdata)
      pst.char(13)
    
      bytefill(@rxdata, 0, BUFFER_2K)
      
      pst.str(string(13, "Send Greeting"))
      StringSend(id, string("Hello from Spinneret!",13,10))
      'pause(10)
    
      
      pst.str(string(13, "Wait for username"))
      repeat
        packetSize := Socket.rxTCP(id, @rxdata)
        pause(200)
        if(packetSize > 0)
          quit
      pst.str(string(13, "Username received"))
      pst.char(13)
      pst.str(@rxdata)
      StringSend(id, string("OK",13,10))
      bytefill(@rxdata, 0, BUFFER_2K)
    
      
    
      pst.str(string(13, "Get file size"))
      repeat
        packetSize := Socket.rxTCP(id, @rxdata)
        pause(200)
        if(packetSize > 0)
          quit
      pst.str(string(13, "File size received"))
    
      StringSend(id, string("OK"))
      
      rxBytes := str.ToInteger(@rxdata)
      bytefill(@rxdata, 0, BUFFER_2K)
      pst.str(string("rxBytes: "))
      pst.dec(rxBytes)
      pst.char(13)
      bytefill(@rxdata, 0, BUFFER_2K)
      
      'StringSend(id, string("Verified! Ready for upload."))
      'return
    
    
      
    
      {{   }} 
      pst.str(string(13, "change directory"))
      SDCard.changeDirectory(@approot) 
      SDCard.changeDirectory(@uploadfolder)
       
      pst.str(string(13, "File Exists?"))
      if(FileExists(@binFile))
        pst.str(string(13, "YES File Exists - DELETE"))
        SDCard.deleteEntry(@binFile)
    
      pst.str(string(13, "Create file"))
      SDCard.newFile(@binFile)
       
      pst.str(string(13, "Open file"))
      SDCard.openFile(@binFile, "w")
    
      
      pst.str(string(13, "File Upload in process"))
         
      repeat while rxBytes > 0
        packetSize := Socket.rxTCP(id, @rxdata)
        if(packetSize > 0)
    
          'end :=  str.MatchPattern(@rxdata, @hashboundary, 0, true)
          'if(end == -1)
            SDCard.writeData(@rxdata, packetSize)
            StringSend(id, string("OK",13,10))
          'else
            'StringSend(id, string("DONE",13,10))
    
          rxBytes := rxBytes - packetSize
          pst.str(string(13, "Bytes Left: "))
          pst.dec(rxBytes)
          
          if(rxBytes == 0)
            StringSend(id, string("DONE",13,10))
            
          pause(200)
          i := 0
        else
          i++
          pause(200) 
        if(i > 100)
          quit    
    
    
      pst.str(string(13, "loops      : "))
      pst.dec(j)
      pst.str(string(13, "rxBytes : "))
      pst.dec(rxBytes)
      
      'pst.str(string(13, "Close file", 13))
      SDCard.closeFile
      
      SDCard.changeDirectory(@approot)
    
      'pst.str(string(13, "Send authentication"))
      'StringSend(id, string("What can I do for you Dave?", 13, 10))
      
      return
    
    PRI GetTime(id) | ptr, headerOffset
      ptr := @udpdata
      'FillTime
      FillHttpDate
      
      bytemove(ptr, string("<p>"),3)
      ptr += 3
    
      bytemove(ptr, @httpDate, strsize(@httpDate))
      ptr += strsize(@httpDate)
      
      'bytemove(ptr, @time, strsize(@time))
      'ptr += strsize(@time)
    
      'bytemove(ptr, string(" (GMT-7)"), 8)
      'ptr += 8
      
      bytemove(ptr, string("</p>"),4)
      ptr += 3  
    
      headerOffset := Response.BuildHeader(Request.GetExtension(id), 200, false)
      Socket.txTCP(id, @txdata, headerOffset)
      StringSend(id, @udpdata)
      bytefill(@udpdata, 0, UPD_BUFFER)
      
      return
      
    PRI GetDir(id) | filenamePtr, ptr, headerOffset, cmd, qfile
    
      'pst.str(string(13, "GetDir", 13))
      ptr := @udpdata
    
    
      'pst.str(string(13, "change dir", 13))
      SDCard.changeDirectory(@approot)
      SDCard.changeDirectory(@uploadfolder)
    
      
      cmd := Request.Get(id, string("cmd"))
      if(strcomp(cmd, string("d")))
        qfile :=  Request.Get(id, string("file"))
        SDCard.deleteEntry(qfile)  
    
      
      'pst.str(string(13, "startFindFile", 13))
      SDCard.startFindFile
      
      'Verify that the file exists
      filenamePtr := 1
      repeat while filenamePtr <> 0
        filenamePtr := SDCard.nextFile
    
        if(strcomp(filenamePtr, string(".")) or strcomp(filenamePtr, string("..")) or strsize(filenamePtr) == 0)
          next
        
        'pst.str(filenamePtr)
        'pst.char(13)
        'pst.dec(strsize(filenamePtr))
        'pst.char(13) 
            
        bytemove(ptr, string("<a href='uploads/"),17)
        ptr += 17
        
        bytemove(ptr, filenamePtr, strsize(filenamePtr))
        ptr += strsize(filenamePtr)
        
        bytemove(ptr, string("'>"),2)
        ptr += 2
        
        bytemove(ptr, filenamePtr, strsize(filenamePtr))
        ptr += strsize(filenamePtr)
        
        bytemove(ptr, string("</a>&nbsp;&nbsp;"),16)
        ptr += 16
    
    
        {
        bytemove(ptr, string("<a href='uploads/"),17)
        ptr += 17
        
        bytemove(ptr, filenamePtr, strsize(filenamePtr))
        ptr += strsize(filenamePtr)
        
        bytemove(ptr, string("'?cmd=d>delete</a>"),18)
        ptr += 18
        }
        bytemove(ptr, string("<br>"),4)
        ptr += 4
    
      SDCard.changeDirectory(@approot)
      
      'pst.char(13)
      'pst.str(@udpdata)
      'pst.char(13)
      
      'pst.str(string(13, "send header", 13))
      headerOffset := Response.BuildHeader(Request.GetExtension(id), 200, false)
      Socket.txTCP(id, @txdata, headerOffset)
    
      'pst.str(string(13, "send data", 13))
      StringSend(id, @udpdata)
      bytefill(@udpdata, 0, UPD_BUFFER)
     
      return
    
    PRI AppendLog(logToAppend)
      
      SDCard.changeDirectory(@approot) 
    
      if(FileExists(@logfile))
        'pst.str(string(13, "LOG: open file for writing", 13))
        SDCard.openFile(@logfile, "A")
      else
        'pst.str(string(13, "LOG: Create new file", 13))
        SDCard.newFile(@logfile)
    
      SDCard.writeData(string("----- Start "),12)
      SDCard.writeData(FillTime, 19)
      SDCard.writeData(string(" -----"),6)
      SDCard.writeData(@crlf_crlf, 2)
      
      'pst.str(string(13, "LOG: Append", 13))
      SDCard.writeData(logToAppend, strsize(logToAppend))
      SDCard.writeData(@crlf_crlf, 2)
      
      SDCard.writeData(string("----- End "),10)
      SDCard.writeData(FillTime, 19)
      SDCard.writeData(string(" -----"),6)
      SDCard.writeData(@crlf_crlf, 2)
    
      'pst.str(string(13, "LOG: Close file", 13))
      SDCard.closeFile
      
    PRI Set(DestAddress, SrcAddress, Count)
      bytemove(DestAddress, SrcAddress, Count)
      bytefill(DestAddress+Count, $0, 1)
    
    PRI Ajax(id)
      pst.str(string(13, "**************************", 13))
      pst.str(@rxdata)
      pst.str(string(13, "**************************", 13))
      return
    
    
      
      
    '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    {  } 
    PRI FillTime | ptr, num
     'ToString(integerToConvert, destinationPointer)
     '00/00/0000 00:00:00
      ptr := @time
      rtc.readTime
      
    
      FillTimeHelper(rtc.clockMonth, ptr)
      ptr += 3
    
      FillTimeHelper(rtc.clockDate, ptr)
      ptr += 3
    
      FillTimeHelper(rtc.clockYear, ptr)
      ptr += 5
    
      FillTimeHelper(rtc.clockHour , ptr)
      ptr += 3
    
      FillTimeHelper(rtc.clockMinute , ptr)
      ptr += 3
    
      FillTimeHelper(rtc.clockSecond, ptr) 
     
      return @time
    
    
    PRI FillHttpDate | ptr, num, temp
     'ToString(integerToConvert, destinationPointer)
     'Wed, 01 Feb 2000 01:00:00 GMT
      ptr := @httpDate
      rtc.readTime
    
    
      temp := rtc.getDayString
      bytemove(ptr, temp, strsize(temp))
      ptr += strsize(temp) + 2
    
      FillTimeHelper(rtc.clockDate, ptr)
      ptr += 3
    
      temp := rtc.getMonthString
      bytemove(ptr, temp, strsize(temp))
      ptr += strsize(temp) + 1
    
      FillTimeHelper(rtc.clockYear, ptr)
      ptr += 5
    
      FillTimeHelper(rtc.clockHour , ptr)
      ptr += 3
    
      FillTimeHelper(rtc.clockMinute , ptr)
      ptr += 3
    
      FillTimeHelper(rtc.clockSecond, ptr)
      
      return @httpDate
    
    
    PRI FillTimeHelper(number, ptr) | offset
      offset := 0
      if(number < 10)
        offset := 1
         
      str.ToString(@number, @tempNum)
      bytemove(ptr+offset, @tempNum, strsize(@tempNum))
      
    {
    PRI toString(id) | i
      pst.str(string("-------------------------",13))
      pst.str(string("Version     : "))
      pst.str(Request.GetVersion(id))
      pst.char(13)
    
      pst.str(string("QueryString : "))
      pst.str(Request.GetQueryString(id))
      pst.char(13)
    
      pst.str(string("Method      : "))
      pst.str(Request.GetMethod(id))
      pst.char(13)
    
      pst.str(string("Depth       : "))
      pst.dec(Request.GetDepth(id))
      pst.char(13)
    
      i := 0
      repeat Request.GetDepth(id)
        pst.dec(i)
        pst.str(string(". Name     : "))
        pst.str(Request.GetPathNode(id, i++))
        pst.char(13)
      
    
      pst.str(string("FileName    : "))
      pst.str(Request.GetFileName(id))
      pst.char(13)
      
      pst.str(string("Name        : "))
      pst.str(Request.GetName(id))
      pst.char(13)
    
      pst.str(string("Extension   : "))
      pst.str(Request.GetExtension(id))
      pst.char(13)
    
      pst.str(string("Content-Len : "))
      pst.dec(Request.GetContentLength(id))
      pst.char(13)
    }   
    PRI Pause(Duration)  
      waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt)
      return
        
    DAT
      approot               byte    "\", 0 
      placeholder           byte    "<!--[content]-->", 0
      tempFile              byte    "temp.htm", 0
      defaultpage           byte    "index.htm", 0
      logfile               byte    "log.txt", 0
      cacheFile             byte    "cache.txt", 0
      binFile               byte    "image.bin", 0
      FS                    byte    "/", 0
      fn                    byte    "filename=", 0
      doublequote           byte    $22, 0
      crlf                  byte    13, 10, 0
      crlf_crlf             byte    13, 10, 13, 10, 0
      uploadfile            byte    $0[12], 0
      divider               byte    "----", 0
      uploadfolder          byte    "uploads", 0
      tempNum               byte    "0000",0
      multipart             byte    "Content-Type: multipart/form-data; boundary=",0
      boundary              byte    $2D, $2D
      boundary1             byte    $0[64]
      hashboundary          byte    "123ABC",0                 
    
    {{
    &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    &#9474;                                                   TERMS OF USE: MIT License                                                  &#9474;                                                            
    &#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
    &#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    &#9474; 
    &#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    &#9474;
    &#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software&#9474;
    &#9474;is furnished to do so, subject to the following conditions:                                                                   &#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;The above copyright notice and this permission notice shall be included in all copies or substantial ions of the Software.&#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          &#9474;
    &#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         &#9474;
    &#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   &#9474;
    &#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         &#9474;
    &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    }}
    
  • Mike GMike G Posts: 2,702
    edited 2011-07-20 15:32
    @worthyamherst, you have the code configured to run all sockets as listeners. If you need one client all the time,

    change this in the DAT section
    tcpMask               byte    %1111 
    
    tcpMask               byte    %0111 
    

    And change this in PUB Initialize | id, size, st
      repeat id from 0 to 3
        InitializeSocket(id)
        Request.Release(id)
        pause(50)
    

    to
      repeat id from 0 to 2
        InitializeSocket(id)
        Request.Release(id)
        pause(50)
    

    And fire up socket 3 as your client.

    The code is designed to return the wayward socket back to a listener depending on the tcpMask.

    You can also remove this stuff for your client method
      tempMask := tcpMask
      tcpMask := SetTcpSocketMaskById(id, 0)
    ...
      tcpMask := tempMask
    

    How you handle socket 3 is up to you.
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-24 20:40
    Is it possible to send additional data back to the Spinneret from the server? The data I'm sending to the server is just numeric data from PING sensors on our project. Having a button on our website that tells our autonomous car to turn on or off or to switch modes would be pretty cool, but I don't know how to exactly pull this off. Can I have the Spinneret send a request to the server and have the server respond with an answer to whether or not the car should be on? Or would it be more efficient to have the same script that receives the data send the on/off/mode stuff? I need information on how your code is opening the sockets and setting them as listeners, or clients, or whatever. I'm not sure at all how all of that works. Once I understand how to receive responses from a connected socket, I will be able to do the rest on my own. If you want to start a new post on this, could you shoot me a PM letting me know where it is? THANK YOU SO MUCH!

    Also, is it possible to have separate cogs utilizing different sockets at the same time?
  • Mike GMike G Posts: 2,702
    edited 2011-07-24 22:23
    Is it possible to send additional data back to the Spinneret from the server?
    In a client server interaction the client makes a request and the server answer with a response . Simply send meaningful data back to the client and not echo the request parameters. That is, update your PHP script to send meaningful data back to the Spinneret.
    Having a button on our website that tells our autonomous car to turn on or off or to switch modes would be pretty cool, but I don't know how to exactly pull this off
    I assume you mean a web site other than content rendered from the Spinneret? Sure, just send a GET or POST request to the Spinneret from your web server.
    Can I have the Spinneret send a request to the server and have the server respond with an answer to whether or not the car should be on?
    Confused, request/response is a core web server function
    I need information on how your code is opening the sockets and setting them as listeners, or clients, or whatever.
    I'll have a detailed write up in about a week. Otherwise read the code and comments. Basically, there is a member tcpMask that turns the listeners off and on.
    0000 = all off
    0001 = Socket 0 is listening
    0011 = Socket 0 and 1 are listening
    
    Once I understand how to receive responses from a connected socket, I will be able to do the rest on my own.
    You lost me... receiving a socket request is a core function of the multi-socket driver. Are you asking, "How do I parse a string?" or "How do I Parse Receive Buffer?"
    Also, is it possible to have separate cogs utilizing different sockets at the same time?
    Yes, I'm not sure that's the most efficient use of resources. I suppose there could be a need though.

    Please don't PM a link to your latest post. I have several folks PMing me... Folks just ask your questions on the forum.
    If you want to start a new post on this, could you shoot me a PM letting me know where it is?

    Click the "Post New Thread" button in the main forum.

    Post your code :(
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-26 12:29
    All of this is probably completely wrong. Can you tell me how close I am though? hahhahaha!

    Spinneret:
    PUB rxdataon(id) | st, size, idx, tempMask
       
     repeat
      tempMask := tcpMask
      tcpMask := SetTcpSocketMaskById(id, 0)
       
      Socket.Close(id)
      pause(delay)
      InitializeSocket(id)
      pause(delay)
    
      'Get My IP
      pst.str(string(13, "Connecting",13))
      Socket.Connect(id)
      pause(delay)
      
       repeat while !Socket.Connected(id) 
      
       pst.str(string(13, "Sending",13))
    
       'StringSend(id, string("GET /test.php?1=", "test1", "&2=", "test2", " HTTP/1.1" , 13, 10))
       StringSend(id, string("GET /helipower.php?1="))
       Stringsend(id, string("1"))
       StringSend(id, string(" HTTP/1.1", 10, 13))    
       StringSend(id, string("Keep-Alive: 115", 13, 10))
       StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
       StringSend(id, string("Connection: keep-alive", 13, 10))
       StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
       StringSend(id, string("Content-length: 23", 13, 10, 13, 10))
       StringSend(id, string("name=test&submit=Submit"))
    
      pst.str(string("sent....recieving response"))
    
      'repeat
       socket.rxTCP(id, @rxdataone)
     
       'str.Start
       
       'str.ToString(@rxdat, @rxdataone)
      
       pst.str(@rxdataone)
    
      
    
      'Reset the socket
      Socket.Disconnect(id)
      Pause(delay)
      
      'Reset the tcpMask
      tcpMask := tempMask
    
      pst.str(string(13, "Repeat", 13))
    
    main
    

    PHP:
    <html><body>
    <?php
    
    
    $a = $_GET['1'];
    
    
    
    echo $a;
    
    
    
    ?>
    </body></html>
    
  • Mike GMike G Posts: 2,702
    edited 2011-07-26 12:48
    I'm not sure what you shooting for? I'm guessing you want the body of the response. Anyway, the code below finds the start of the message body.
    PUB GetWfi(id) | st, size, idx, tempMask
      pst.str(string(13,"Get WFI!",13))
      tempMask := tcpMask
      tcpMask := SetTcpSocketMaskById(id, 0)
    
      Socket.Close(id)
      pause(delay)
      InitializeWfiSocket(id)
      pause(delay)
    
      'Get My IP
      pst.str(string(13, "Getting Assigned IP ",13))
      Socket.Connect(id)
      pause(delay)
      repeat while !Socket.Connected(id)
    
      pst.str(string(13, "Sending Header ",13))
    
      StringSend(id, string("GET /helipower.php?1=1 HTTP/1.1", 13, 10))
      StringSend(id, string("Keep-Alive: 115", 13, 10))
      StringSend(id, string("Host: wbuffalo.workforceinnovators.org", 13, 10))
      StringSend(id, string("Connection: keep-alive", 13, 10))
      StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) 
      StringSend(id, string("Content-length: 34", 13, 10, 13, 10))
      StringSend(id, string("1=post_test&2=from_mikeg_spinneret"))
    
      
      'repeat until size := Socket.rxTCP(id, @rxdata)
      'pst.str(@rxdata)
      'AppendLog(@rxdata)
    
      repeat until size := Socket.rxTCP(id, @rxdata)
      'Find and print the message body
      idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true)
      pst.str(@rxdata+idx+4)
    
    
      'Reset the socket
      Socket.Disconnect(id)
      InitializeSocket(id)
      
      'Reset the tcpMask
      tcpMask := tempMask
    

    Response header with message body
    HTTP/1.1 200 OK
    Date: Tue, 26 Jul 2011 19:41:20 GMT
    Server: Apache
    X-Powered-By: PleskLin
    Content-Length: 32
    Connection: close
    Content-Type: text/html
    
    <html><body>
    1</body></html>
    

    The response is exactly how the PHP script is coded. You could remove the html and body tags and only return the "1" if you like. Again I'm not really sure what you're trying to do.
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-26 12:54
    I want to be able to press a button on the website to send whether or not out project should be on or off. I thought to send something...and then have a response as to whether it should be on or not...depending on if the "Power Button" is pressed or not. How could I use the return from the server to set a variable in the SPIN code I could use to control the automated RC helicopter we're working on?
Sign In or Register to comment.