User manual
mikroBasic PRO for PIC32
MikroElektronika
433
‘ 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
‘ get 10 rst bytes only of the request, the rest does not matter here
for i = 0 to 10
getRequest[i] = Spi_Ethernet_getByte()
next i
getRequest[i] = 0
‘ copy httpMethod to ram for use in memcmp routine
for i = 0 to 4
txt[i] = httpMethod[i]
next i
if(memcmp(@getRequest, @txt, 5) <> 0) then ‘ only GET method is supported here
result = 0
exit
end if
Inc(httpCounter) ‘ one more request done
if(getRequest[5] = “s”) then ‘ if request path name starts with s,
store dynamic data in transmit buffer
‘ the text string replied by this request can be interpreted as javascript
statements
‘ by browsers
result = SPI_Ethernet_putConstString(@httpHeader) ‘ HTTP header
result = result + SPI_Ethernet_putConstString(@httpMimeTypeScript)‘ with text MIME type
‘ add AN0 value to reply
WordToStr(ADC1_Get_Sample(0), dyna)
txt = “var AN0=”
result = result + Spi_Ethernet_putString(@txt)
result = result + Spi_Ethernet_putString(@dyna)
txt = “;”
result = result + Spi_Ethernet_putString(@txt)
‘ add AN1 value to reply
WordToStr(ADC1_Get_Sample(1), dyna)
txt = “var AN1=”
result = result + Spi_Ethernet_putString(@txt)
result = result + Spi_Ethernet_putString(@dyna)
txt = “;”
result = result + Spi_Ethernet_putString(@txt)