#2 FreeRTOS web server

Some FreeRTOS demo applications include a tiny web server capable of handling dynamic web pages content. The web server source code is usually located inside the webserver directory within the demo application. This section is based on the ARM7_AT91SAM7X256_Eclipse demo project in FreeRTOS 6.1.1.
.webserver\ -> source code
.webserver\httpd-fs -> web server filesystem

The web server is a pretty neat application. Adding a web page is done by dropping the new HTML page inside the webserver\httpd-fs directory and recompiling the filesystem using the perl script .webserver\makefsdata, example:

$ perl makefsdata
Adding file 404.html
Adding file index.html
Adding file index.shtml
Adding file io.shtml
Adding file my_page.shtml
Adding file stats.shtml
Adding file tcp.shtml

The script generates the file .webserver\httpd-fsdata.c that is later compiled with the application.

I. Dynamic web pages

Adding dynamic content to the web page is done by using a special tag that is known to the web server. The tag is composed of the 2 symbols %! followed by the cgi table entry name. For instance, the web page stats.shtml includes the tag: %! rtos-stats:

<font face="courier">
<pre>Task  State  Priority  Stack #<br>*********************************<br>
%! rtos-stats

When crossing such a tag, the web server parses the CGI table to find a match. The table entries are declared in .webserver\html-cgi.c. The entry matching the rtos-stats tag is declared as following:

HTTPD_CGI_CALL(rtos, "rtos-stats", rtos_stats );

static unsigned short
generate_rtos_stats(void *arg)
	sprintf( cCountBuf, "<p><br>Refresh count = %ld", lRefreshCount );
	vTaskList( uip_appdata );
	strcat( uip_appdata, cCountBuf );
	return strlen( uip_appdata );

PT_THREAD(rtos_stats(struct httpd_state *s, char *ptr))
  PSOCK_GENERATOR_SEND(&s->sout, generate_rtos_stats, NULL);  

The routines called when crossing the rtos-stats tag are shown above. Basically, the application must return the dynamic data using the uip_appdata data buffer. It's that simple!