How to build firmware architecture for an IOT device

How to build firmware architecture for an IOT device

Arduino Jan 16, 2022

Hello People. This article discusses how to build firmware architecture for an IOT device. Generally, a firmware in an IOT device will be responsible for reading sensor data, controling the relay shield, connecting to WiFi access point, serving a web dashboard application.

The picture below shows you the code architecture of the firmware.

How to build firmware architecture for an IOT device

We will briefly explore the code architecture. Let us go through each section. The hardware setup is shown in the figure below.

Hardware setup

We have four relays which we control using GPIO pins of the Node MCU module. We also have two sensors whose data we read through the digital input of Node MCU module.

Are you looking to start your business in the electric vehicle industry? We provide software development, web application development, mobile application development, charging stations management app, electric vehicle fleet management software development, cyber security and all software services. Please check our home page here

Ok. Let's get back to the article.

There are three main functions that this Node MCU or ESP 8266 or any other IOT device performs. They are 1.Serving the web application from its flash memory. It handles the web socket messages and display the data properly. 2. Control the relays. 3. Read temperature and humidity data and connect to wifi to be able to be accesed from anywhere in the world.

It contains five fundamental functions which are color coded in the above architecture diagram. Let us see the MAIN flow. After the Wifi is ON, the setup lodas configuration, sets up the wifi connection, sets up the sensors, sets up the relays and sets up the web server. Then the loop of Wifi and Sensors begin. Finally we get Input.

Now discussing about Wifi flow, once Wifi is ON, it gets the IP info. If LED is timed out, the state of LED changes. Talking about the Sensors flow, sensors setup gets executed after wifi is setup. It sets poll interval and initiates DHT sensor. Sensors loop starts after the wifi loop. The sensor prepares a result and stores it in variables. It reads the data and sets an input string.

Relay flow is simple. It sets up relay pins and sets teh initial relay states. Web server flow begins after the relay setup. It mounts the FS and websocket server is added and started.

Hope this article on how to build firmware architecture for an IOT device is useful to you. Please read How to visualize IOT sensor data