Efficient web server technology for resource-constrained microcontrollers
Some time ago we published an article titled A fresh look at embedding a web server, where we suggested using WebSockets instead of HTTP with its traditional GET and POST commands. One commenter criticized the article for not being suitable for a broad category of small microcontroller based embedded systems.
The WebSocket protocol when used correctly uses fewer resources than a traditional web server. In fact, we believe WebSockets is the only viable option if you ever plan on TLS enabling the embedded web server. You may already be using an embedded web server in your device, but enabling TLS on a standard web server for a resource-constrained device typically ends in disaster. To understand why TLS creates such a problem for standard web server technology, see our tutorial When Not to Embed a Web Server in a Device.
Modern Web Application Reference Design for Microcontrollers
We recently committed our Embedded HTTP and WebSocket Server to GitHub. The Embedded HTTP and WebSocket server, called the Minnow Server, has been specifically designed for tiny microcontrollers with limited resources.
More importantly, we also included a reference example that shows how to build a modern real time web user interface for device management. The web application is a so called Single Page Application (SPA) that exclusively uses the WebSocket protocol for device management. The HTTP protocol is used only for loading the SPA. In other words, HTTP is initially used by the browser when loading the application on demand from the device.
The reference example includes real time updates of LEDs and a thermostat gauge, and it shows how to do firmware upload over WebSockets. The complete SPA requires only 41 Kbytes of flash memory storage space. Also, the WebSocket server requires very little RAM for the communication.
Get Started with the Minnow Server
The Minnow Server is designed for small microcontrollers, but since the reference example is primarily designed for educational purposes, we have limited the ready to use build environment to Windows and Linux. You can port the application to an embedded system, but it makes more sense to just use the design ideas in the reference example. You may of course use the generic parts "as is".
Although the Minnow Server can be set up to manage several connections, the reference example is set up to manage one connection at a time. Attempting to connect a new browser window while another browser window is using the one and only WebSocket connection will not work.
Wilfred Nilsen, Founder & CTO of Real Time Logic, has 28 years' experience in designing embedded software. Powered by a vision of connected embedded systems, he designed the Barracuda Application Server, tailoring it for the small footprint, real-time needs of embedded microprocessors.