Instructions
396Libraries
© 2013 Conrad Electronic
URL (CGI) Variables
When there are no URL variables specified for a web request, the whole process runs in the back-
ground, and there must be no program interaction. If a URL variable is present (e.g. "?var0=5") web
server checks if there is variable name that corresponds to the scheme "var" + number. The number
must not exceed the maximum index of defined dynamic variables. If the scheme is met, the value
"5" is assigned to the dynamic variable. Then the integer variable a gets the value 5.
There is a special URL ("setvars.js") which takes only the URL variables, but does not return any
website content. With that mechanism variable content can be transferred to Javascript without gen-
erating much TCP/IP traffic.
A variable can be modified only via URL, when WEB_SetDynVar () is called with the
DYN_CGIVAR flag set. This allows normal variables to be protected from a change from the outside.
JSON
If you want to work with JavaScript, dynamic variables can be output as a JSON list. For this pur-
pose, in the definition of WEB_SetDynVar () the flag DYN_JSONVAR has to be set. Access to
"getvars.js" then provides the JSON data. E.g: "{" 1 ":" 123 "," 3 ":" 0 "}". This is a list of two dy-
namic variables with the indices 1 and 3. The first variable has the content "123", the second variable
contains "0".
Interaction
In normal operation, the main loop of the program is queried continuously with WEB_GetRequest(), if
there is a request with an URL variable present. There is a request, when the return parameter is un-
equal to zero. You can then check the hash of the file name with WEB_GetFileHash() and evaluate
the passed URL variables. Thereafter, the output variables (dynamic variables of the site) should be
set to new values according the program logic. At the end of request the web server is signaled with
WEB_ReleaseRequest() that the Website should be shipped to the browser.
5.27.1 Webserver Hints
Web Server Checklist
The invoked Web pages must have been copied to the micro SD card, and the card must be inser-
ted in the SD card slot of the AVR32Bit Unit.
For the SD card, only the FAT file system is supported (see FAT support).
The web server is started after ETH_StartWebserver() is called from the user program. The TCP/IP
port in the web browser (default: 80) must match the port in the call to ETH_StartWebserver.
The number of dynamic variables used in WEB_SetDynVar must correspond with the definition in
the WEB_BUF macro and dynvar_cnt in WEB_StartServer.
When stopping the program with the Start/Stop button, the lwIP TCP/IP stack can get in a
state, where not all dynamic memory for the current connection is released. This memory may be
missing when you restart the program. If in doubt when encountering problems, press the reset but-
ton to initiate a complete system reboot.