User manual
494
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
“str=”+chr(34)+chr(34)+”; “+
“for(i=0;i<4;i++)”+
“{str+=”+chr(34)+”<tr><td bgcolor=yellow>LED #”+chr(34)+”+i+”+chr(34)+”</
td>”+chr(34)+”; “+
“if(PORTD&(1<<i)){str+=”+chr(34)+”<td bgcolor=red>ON”+chr(34)+”;}”+
“else {str+=”+chr(34)+”<td bgcolor=#cccccc>OFF”+chr(34)+”;}”+
“str+=”+chr(34)+”</td><td><a href=/t”+chr(34)+”+i+”+chr(34)+”>Toggl
e</a></td></tr>”+chr(34)+”;}”+
“document.write(str) ;”+
“</script>”+
“</table></td></tr></table>”+
“This is HTTP request #<script>document.write(REQ)</script></BODY></HTML>”
dim getRequest as byte[15] ‘ HTTP request buffer
dyna as char[30] ‘ buffer for dynamic response
httpCounter as word ‘ counter of HTTP requests
txt as string[11]
‘ *******************************************
‘ * user dened functions
‘ *
‘ *
‘ * this function is called by the library
‘ * the user accesses to the HTTP request by successive calls to Spi_Ethernet_
getByte()
‘ * the user puts data in the transmit buffer by successive calls to Spi_Ethernet_
putByte()
‘ * the function must return the length in bytes of the HTTP reply, or 0 if nothing to
transmit
‘ *
‘ * if you don’t need to reply to HTTP requests,
‘ * just dene this function with a return(0) as single statement
‘ *
‘ *
sub function Spi_Ethernet_UserTCP(dim byref remoteHost as byte[4],
dim remotePort, localPort, reqLength as word, dim byref ags as TEthPktFlags) as word
dim i as word ‘ my reply length
bitMask as byte ‘ for bit mask
txt as string[11]
result = 0
‘ should we close tcp socket after response is sent?
‘ library closes tcp socket by default if canClose ag is not reset here
‘ canClose = 0 ‘ 0 - do not close socket
‘ otherwise - close socket
if(localPort <> 80) then ‘ I listen only to web request on port 80
result = 0
exit
end if