Thanks to the HTTP server, it's possible to communicate with the a card with the a web-server, with any Operating System.
The server is able to draw a file directly from the SD memory and send it to the destination.
Also a request can interact with the software (and so with the hardware) essentially in 2 ways: in "reading", asking the dates through a CGI page, and a "writing" or rather sending the commands.
A CGI (Common Gateway Interface) page is just a html page, that can contain the escape % character followed by a decimal number from two ciphers; this number identifies a variable that will be requested to the program.
In particular is invoked the HTTPGetVar function that is found in the MainDemo.c file:
WORD HTTPGetVar(BYTE var, WORD ref, BYTE* val)
the first parameter identifies the variable about which is requested the value; the second parameter , used for the variables composed from more byte; the last parameter points to the location where we'll write the variable value (we'll write the byte ref-exempt).
The return value it is HTTP_END_OF_VAR if we sent the byte from the variable var, otherwise will be the pointer of the next byte to send, or rather ref+1.
Let's see a short example:
<b>Variabile 1</b>: %01 <br> <b>Varibile 2</b>: <em>%02</em>
In this CGI file there are two variables, so HTTPGetVar will be called with var even to 1, then will return through the val, for example the 'A' character. Successively is recalled the HTTPGetVar, but with var equal to 2; this time let's suppose that the date is a line, that's why this function will be called many times until will be arrived the line term (ex. "Ciao").
At this point the server can send the answer to anyone who asked for the page, that will receive:
<b>Variabile 1</b>: A <br> <b>Varibile 2</b>: <em>Ciao</em>
If to the requested page we add the parameters will be possible to follow the actions to the software.
A request with the parameters has this aspect:
http://10.0.0.6/pagina.htm?param1=val1¶m2=val2
This request is automatically analyzed by the HTTP server and passed to the HTTPExecCmd method, array subform of strings.
The HTTPExecCmd method is defined:
void HTTPExecCmd(BYTE** argv, BYTE argc)
So in the example made first, argv will be:
argv[0] = pagina.htm argv[1] = param1 argv[2] = val1 argv[3] = param2 argv[4] = val2
while argc (elements number) will be 5. Like this, writing the opportune code inside of this method, the PIC can follow different functions upon the received parameters.
Also to the end of the method, argv[0] must contain the number from the page to return, that can be that requested (ex. page.htm) or another one.
|