IoT and Embedded Web Server technologies both have their plusses and minuses. In this hands on article, we will show how it is possible to re-use the device management application for both solutions. You may compile the code we present below and connect to the IoT testing server we have setup.
Embedded Web Servers have been used for device management long before IoT was coined, and it is still very popular due to its simplicity. Just take your home router as an example, which provides a web interface for all the router settings.
The benefit with using an Embedded Web Server is that it does not rely on any third party products that may fail, thus making it more reliable and always available on the local network where the device is deployed.
The negative with an Embedded Web Server powered device is that it is not easy to control the device outside of the local network where the device is deployed. Technically challenging solutions such as setting up a pinhole (port forwarding) in the router is possible, but it is not an ideal solution.
IoT has many benefits such as being able to manage and supervise multiple devices in multiple locations. With IoT, the devices typically act as a network client and connect to an online IoT cloud server. A user does not directly control a device, but must first navigate to the cloud solution for getting access to the device(s).
The negative with an IoT solution is for devices that are more often controlled from the network where they are deployed. The IoT round-trip slows down communication, making some real time applications too slow. Should the IoT cloud server or its network infrastructure go down, the devices become impossible to control.
Reaping the benefits of both solutions and eliminating the negatives is to design a device that can both provide a local web interface via an embedded web server and be controlled via an IoT cloud server. However, doing so has traditionally incurred extra complexity and development time.
Is it possible to provide both solutions and re-use the device management application for both solutions?
Yes it is possible, but doing so requires re-thinking the traditional way of designing web based device management applications. Instead of using the standard HTTP GET/POST for performing the actual commands, a persistent WebSocket connection is used. For this to work, the HTML application must be designed as what is known as a Single Page Application (SPA).
To show that it is indeed possible to re-use an SPA for both local management directly via an embedded web server and remotely via IoT, we created an online testing server you may use. The testing server is available at the following URL:
IoT Testing Server: https://minnow.realtimelogic.com/
The simulated device code can be downloaded to your computer and compiled as follows:
The above commands download the Minnow Server (WebSocket server) from GitHub and compile the Minnow Server reference example in IoT mode by the make command IOT=true.
The above commands require that you have git, make, and gcc installed on your host computer. If you are using Windows, use the Windows 10 Linux subsystem or use the online C compiler we have setup by navigating to:
Online C compiler and IoT testing server: https://minnow.realtimelogic.com/IoT-Bridge-Demo.html
When the Minnow Server runs, the server connects to the online IoT server after 3 seconds if the Minnow Server is not controlled locally.
When the Minnow Server runs, use your browser and navigate to http://localhost:#, where # is the port number the server is listening on. You may then control the device using a local connection. The default credentials are user "root" and password "password.
You may also control the device using the online server, but make sure to close the local connection first. After closing the connection, the server will connect to the online IoT server after 3 seconds. You may then click the link presented on the online IoT server. Click this link and login.
See the article Creating Single-Page Apps with the Minnow Server for details on how the reference example works.
The following video, starting at 4:20, shows an ESP8266 microcontroller being controlled via the online IoT server. See the Minnow Server's GitHub documentation for details on installing the software on a microcontroller.