Web applications on embedded hardware

January 9, 2011. code, embedded, thttpd, lua, haserl

Scenario: You have been tasked to provide a web interface for a embedded device [1] that allows the user to set/modify configurations and may be even look at log files, visualize some data collected by the said device.

Usually, this is where the typical embedded software developer groans under his breath and starts writing a CGI app using the web development skills he picked up from his electronics professor’s website at the university.

Web apps on embedded hardware, at least in my experience, tend to be:

Using C to develop web applications is like cleaning the floor with tooth brush. You can really get to all the corners, but it takes a patient man with a lot of time.

I was recently tasked with something similar in nature. The web application should allow the user to set network parameters like ipaddress, http proxy etc.,

To write an application like this, you need:

Right now, I’m looking at a stack comprising of

thttpd as the web server

thttpd is a simple, small, portable, fast, and secure HTTP server. It is quite easy to install and configure. It goes to great lengths to protect the web server machine against attacks and breakins from other sites. It can run CGI applications.

Lua as the programming language

Lua a lightweight, powerful and featureful programming language which is the top choice when in comes to providing scripting interface to larger applications (eg: World of Warcraft , Adobe lightroom). There are millions of lines of code written by both professional programmers and hobbyists with limited programming training that is used to enhance and alter program behaviour at run time.

Lua is very lean in terms of memory and storage requirements. The entire source code weighs in under 200KB in compressed format.

haserl CGI programming shell

Haserl is a small program that uses shell or Lua script to create cgi web scripts. It is intended for environments where PHP or ruby are too big. The haserl binary typically compiles to less than 20KB (stripped). The lua language adds less than 150K when linked in statically.

In the next post, we will look at installing the entire stack from source on a linux machine, compiling and running simple CGI applications and later, we will develop a “real” application that can be used to set/modify the “HTTP Proxy” setting of a device, which is often required when devices are deployed behind restrictive fire walls.

[1] The term embedded device can be used refer to everything from a device with 1k RAM to newest plug computing devices with 1GB RAM/1GHz CPU. I’m referring to hardware in the range of 64MB RAM/200-400MHz CPU which are capable of running embedded versions of mainstream OSes like Linux or BSD.