Starting with Peter's example server code, I have expanded it to make a more generic web server.
I haven't tested all file types yet but so far, all is good.
You will need to modify it for any form data that needs acting on.
OPTION EXPLICIT
OPTION DEFAULT INTEGER
DIM buff%(512)
CONST maxargs=20
CONST html_def$ = "index.html" ' default landing page
DIM hit_count
DIM mystring$="PicoMite Web Test"
DIM FLOAT mytemp, myhumid, oldtemp, oldhumid
DIM mytime$
DIM INTEGER allrdg, badrdg
TIMER = 3000
'date$ = "01-04-2000"
'on error skip
WEB ntp 11
'if date$ = "01-04-2000" then print "OOPS!"
PRINT "Ready ";DATE$
WEB TCP INTERRUPT gotrequest
DO
IF TIMER > 3000 THEN doread ' background processing to gather data
LOOP
'
SUB gotrequest
LOCAL p%, t%, a%, s$, i, nparams, page$, page_ext$, cons$
LOCAL arg$(1,maxargs-1)
FOR a%=1 TO MM.INFO(MAX connections)
IF NOT MM.INFO(TCP request a%) THEN cons$= cons$ + "-" :CONTINUE FOR
LONGSTRING CLEAR buff%()
WEB TCP READ a%,buff%()
INC hit_count
IF LLEN(buff%()) THEN
cons$=cons$+"*"
page$=parsehtmldata$(nparams,buff%(), arg$())
IF page$ = "" THEN page$ = "index.html"
PRINT STR$(hit_count,7,0)+" "+TIME$+" "+page$
IF INSTR(page$,".") THEN
page_ext$ = LCASE$(MID$(page$,INSTR(page$,".")+1))
ELSE
page_ext$ = ""
ENDIF
' process arguments before returning page with updated results
FOR i=0 TO nparams%
' Print arg$(0,i),"=",arg$(1,i)
IF arg$(0,i)="RB" THEN ' setting for radio button
'
ENDIF
IF arg$(0,i)="RESET" AND arg$(1,i)="YES" THEN 'Reset maxmin
'
ENDIF
NEXT i
IF MM.INFO$(FILESIZE page$) > 0 THEN ' file does exist.
SELECT CASE page_ext$
CASE "html", "htm"
WEB TRANSMIT PAGE a%,page$
CASE "ico"
WEB TRANSMIT FILE a%,page$,"image/vnd.microsoft.icon"
CASE "jpg"
WEB TRANSMIT FILE a%,page$,"image/jpeg"
CASE "png"
WEB TRANSMIT FILE a%,page$,"image/png"
CASE "gif"
WEB TRANSMIT FILE a%,page$,"image/gif"
CASE "bmp"
WEB TRANSMIT FILE a%,page$,"image/bmp"
CASE "js"
WEB TRANSMIT file a%,page$,"script/javascript"
CASE "txt", "csv", "bas"
WEB TRANSMIT file a%,page$,"text/plain"
CASE "cgi"
WEB TRANSMIT file a%,page$,"application/x-httpd-cgi"
CASE ELSE
s$=LGETSTR$(buff%(),1,MIN(255,LLEN(buff%())))
PRINT s$
WEB TRANSMIT PAGE a%,"notfound.html"
WEB TRANSMIT code a%, 404
END SELECT
ELSE
WEB TRANSMIT PAGE a%,"notfound.html"
PRINT "404 "+page$
WEB TRANSMIT code a%, 404
ENDIF
ELSE
cons$ = cons$+"0"
ENDIF
NEXT a%
PRINT "status = "+cons$
' - = no conection, * = conection with data, 0 = connection but no data
END SUB
FUNCTION parsehtmldata$(paramcount AS INTEGER, inbuf() AS INTEGER, arg$())
CONST starttext$="HTTP"
LOCAL a$,b$
LOCAL INTEGER buf(BOUND(inbuf()))
LOCAL INTEGER inpos,startparam,processargs
paramcount=0
inpos=LINSTR(inbuf(),"GET /",1)
IF inpos=0 THEN
parsehtmldata$=""
ELSE
LONGSTRING MID buf(),inbuf(),inpos+5
inpos=LINSTR(buf(),starttext$,1)
IF inpos>2 THEN 'page request found
inpos=inpos-2
a$=LGETSTR$(buf(),1,inPos)
inpos=INSTR(a$,"?")
IF inpos<>0 THEN 'parameters found
processargs=1
parsehtmldata$=LEFT$(a$,inpos-1)
a$=MID$(a$,inpos+1)
DO
arg$(0,paramcount)=""
arg$(1,paramcount)=""
inpos=INSTR(a$,"=")
startparam=1
arg$(0,paramcount)=MID$(a$,startparam,inpos-startparam)
startparam=inpos+1
inpos=INSTR(a$,"&")
IF inpos<>0 THEN
arg$(1,paramcount)=MID$(a$,startparam,inpos-startparam)
a$=MID$(a$,inpos+1)
paramcount=paramcount+1
ELSE
arg$(1,paramcount)=MID$(a$,startparam)
paramcount=paramcount+1
processargs=0
ENDIF
LOOP WHILE processargs
ELSE
parsehtmldata$=a$
ENDIF
ELSE ' no page requested
parsehtmldata$= html_def$ '"index.html"
ENDIF
ENDIF
END FUNCTION
SUB doread
BITBANG HUMID GP17, mytemp, myhumid
IF mytemp > 999 THEN
mytemp = oldtemp
myhumid = oldhumid
' print "!";
badrdg = badrdg + 1
ELSE
oldtemp = mytemp
oldhumid = myhumid
' print "*";
ENDIF
allrdg = allrdg + 1
mytime$ = TIME$+" "+DATE$+" "+STR$(badrdg)+"/"+STR$(allrdg)
TIMER = 0
END SUB
The code to read my DHT22 is included and runs every 3 seconds but that doesn't stop the normal actions of the server.
It can be bypassed if not required.
Jim