Fiddling with MikeG's server code.
Oldbitcollector (Jeff)
Posts: 8,091
Been doing some fiddling with MikeG's webserver code.
I may have found a "best of both worlds" way to add some direction spin-to-html controls along with the clever .js stuff that is currently in it.
Here's my changes
I may have found a "best of both worlds" way to add some direction spin-to-html controls along with the clever .js stuff that is currently in it.
Here's my changes
PRI Dispatcher(id) | bypass { } bypass := 0 '' Spin code Generated webpage '' Checks for commandline entries if(strcomp(Request.GetName(id), string("hello"))) Index(id) DisplayStuff(id) bypass:=1 '' Don't look for actual file. 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 if bypass == 0 StaticFileHandler(id) return { } PRI Index(id) pst.str(string(13, "Index Processor", 13)) 'pst.str(string("led := ")) led:=str2dec((Request.Get(id, string("led")))) 'pst.dec(led) if led == 208 pst.str(string("LED is OFF")) outa[23]:=0 if led == 218 pst.str(string("LED is ON")) outa[23]:=1 pst.char(13) pst.str(string("this := ")) pst.str(Request.Get(id, string("this"))) pst.char(13) return { } PRI DisplayStuff(id) | headerLen ''Build HTML Header headerLen := Response.BuildHeader(Request.GetExtension(id), 200, false) Socket.txTCP(id, @txdata, headerLen) StringSend(id, string("<form>",13,10)) StringSend(id, string("<input type=radio name=led value=1 /> Led On<br /> ",13,10)) StringSend(id, string("<input type=radio name=led value=0 /> Led Off ",13,10)) StringSend(id, string("<form>",13,10)) StringSend(ID, string("<input type=submit /> Change the State of LED.")) PUB str2dec(stri) | index2 result := 0 repeat index2 from 0 to strsize(stri) result *= 10 result += byte[stri][index2] - "0"
Comments
Here's the complete archive. My changes/additions are visible if you access http://localserver/hello.htm
My demo of this is running at http://spinneret.propellerpowered.com/hello.htm
I've setup a simply non-existent "hello.htm" that will switch the LED on and off. It's not perfect by any stretch, but it does work, providing an additional method of interfacing spin to the displayed webpage. I'm still catching up on the AJAX stuff, so my brain hasn't completely wrapped around Mike's methods yet.
Jeffs_hack_of_MikeG_Server.zip
OBC
I find I'm spending most of my time trying to keep up with all the nice contributions and trying to understand what's going on and how to bring good ideas together, so when something pulls stuff together and post source, it really makes things easier for me.
P.S. Kudos to MikeG also!!! (and many others too)