Question

I have an embedded device running a slimmed down version of a HTTP server. Currently, it can display static HTML pages. Here is an example of how it displays a 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 like to do is display dynamic content, e.g. a reading from a sensor. What I thought of so far is to have the page refresh every once in awhile with

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

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

Is there a way I can do this without having to refresh the page constantly?

Was it helpful?

Solution

You can try the following (from my experience) approach: - Divide static and dynamic content, minimize dynamic content.

  • Create a pseudo CGI interface, i.e. URL your_embedded_site/sensor.cgi should be bound to generation of the 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 just (that's all about your 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 to request periodically your_embedded_site/sensor.cgi. Note that javascript is generally browser dependent and may be switched off, java applet will also require additional static content - some *sensor_reader.class" but it has extraordinary freedom in presenting data and extending simple reading and showing with more features.

This allows to organize communication in very efficient way, instead of reloading of the full page: part of code - user front end - will be executed in browser, other part - back end - on the embedded device.

OTHER TIPS

Please do not use a Java applet to provide this.

AJAX and Javascript client-side make this kind of thing easy, without the nastiness of an embedded applet.

Where "nastiness" can include:

  • Java security issues
  • Java runtime mismatches
  • increased payload size (applets are large, compared to snippets of Javascript code)
  • speed issues (it can be slow to start up the applet)
  • web page is harder to maintain
  • and so on.

In summary: it's 2013, just use Javascript and AJAX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top