Can I upload from Spinneret to a remote server?
Moskog
Posts: 556
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?
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?

Comments
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.
Sure, if the login is not https:. I don't think anyone has developed SSL code to-date.
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.
If what you are saying is correct, then you can not use the Spinneret to connect to your web server.
----- 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�Essentials�(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�Essentials�(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 := tempMaskI don't know why I have to keep saying this... but if you want help post your source code.
<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.
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 := tempMaskPost your code... geez I'm trying to help you man!
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"))You know the drill, post your problem code, call when you say you will, be considerate to others...
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 := tempMaskwe were using the StringMethods object, but it wasn't working out very well.
@number is a pointer to the input number
@tempNum is the destination pointer. Where the ASCII string is written
See the StringMethods object for more information.
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.
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"))It's much easier to answer your question when you post the problem code.
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 := tempMaskCON _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> "),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 {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial ions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}change this in the DAT section
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
How you handle socket 3 is up to you.
Also, is it possible to have separate cogs utilizing different sockets at the same time?
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.
Confused, request/response is a core web server function
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.
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?"
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.
Click the "Post New Thread" button in the main forum.
Post your code
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)) mainPHP:
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 := tempMaskResponse header with message body
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.