Embedded webserver in C

Ermers Consultancy was presented the following research question: We have a measuring system on a ship, based on an ARM-9 C environment. We want to download measurements to a Host system. This host system is located at another location, only an ethernet connection is available. Also, we want to upload configuration files to the system. How to proceed?

After initial investigation it turned out that the embedded system already had a tcp-based subsystem. Therefor it was decided to build a small httpd-like deamon. This way, it is possible to use any (modern) browser to perform the tasks needed. There are quite a few examples on the internet which implement a http protocol in C, but some only do very basic stuff (only http-get), are based on (non-available) threading libraries and most of the time, don't fill the needs for up- and downloading (Content-Disposition: attachment) facilities.

So, a small C-library was written, implementing a http server with rest capabilities. Also, a javascript / jquery website example is provided. The library has an abstraction layer, so that it can be implemented on any platform having some basic file i/o and tcp facilities. In writing the library, it was simultaneous tested on a Windows platform and on an ARM9 linux platform. 

As with any embedded webserver, it is now possible to also control 'hardware-things' over the web. For now, only some direct measuring is implemented, but this can easily be expanded. This is part of the AJAX call, which runs every second:

function onSecond()
  var cmdurl = "sys/hdlf/23/2";
  $.getJSON(cmdurl, function (data) {
    document.getElementById("lblIdRoll").innerHTML = "Roll:"+data[0];
    document.getElementById("lblIdPitch").innerHTML = "Pitch:"+data[1];


 Techniques Used

  • C programming.
  • Http protocol implementation. (RFC 7230-7235)
  • Javascript/Jquery/Ajax/JSON
  • IDEs used: Graf - Syteco GDS, Pelles C