http - Display dynamic content from embedded web server -


i have embedded device running slimmed down version of http server. currently, can display static html pages. here example of how displays static html page:

   char *text="http/1.0 200 ok\r\ncontent-type: text/html\r\n\r\n"           "<html><body>hello world!</body></html>";    ipwrite(socket, (uint8*)text, (int)strlen(text));    ipclose(socket); 

what i'd display dynamic content, e.g. reading sensor. thought of far have page refresh every once in awhile

<meta http-equiv="refresh" content="600"> 

and use sprintf() attach sensor reading text variable response.

is there way can without having refresh page constantly?

you can try following (from experience) approach: - divide static , dynamic content, minimize dynamic content.

  • create pseudo cgi interface, i.e. url your_embedded_site/sensor.cgi should bound generation of following http response:

sprintf(cgi_str, "http/1.0 200 ok\r\ncontent-type: text\r\ncontent-length: %d\r\n\r\nvalue=%02d", 8, sensor_value);

or (that's design considerations):

sprintf(cgi_str, "http/1.0 200 ok\r\ncontent-type: text\r\ncontent-length: %d\r\n\r\n%02d", 2, sensor_value);

  • use simple javascript or small java applet request periodically your_embedded_site/sensor.cgi. note javascript browser dependent , may switched off, java applet require additional static content - *sensor_reader.class" has extraordinary freedom in presenting data , extending simple reading , showing more features.

this allows organize communication in efficient way, instead of reloading of full page: part of code - user front end - executed in browser, other part - end - on embedded device.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -