Introduction
IoT
You cannot have IoT without your devices having some connection to the internet. What makes a typical IoT device is hard to define since they come in so many forms. They have existed in various forms since the 1980s and became more widespread since the first decade of the 21st century. What truly makes IOT powerful is when you can have a relatively small and cheap device, often battery-powered, with a wireless internet connection. That’s why we will focus on embedded devices which can directly connect wirelessly to a WWAN or WLAN. Since the 2010’s various low-cost microcontrollers with embedded radio’s have been released. This has enabled developers to easily integrate an internet connection into their devices.
Embedded IoT devices can have several ways to wirelessly connect to the internet, such as:
- WiFi
- An embedded GSM modem
- LoRa
- Sigfox
Each of these technologies has their own ups and downs. WiFi clearly has some big advantages since it is so widely available and doesn’t require a SIM card or data plan. But WiFi has several problems.
- A WiFi channel can become saturated when too many devices are using it. Multiple WiFi networks can use the same channel and different technologies can use the same frequency range.
- The range is limited.
A conventional solution to this problem is to add new access points, which costs time and money to set up.
Mesh network to the rescue
A mesh network allows each device in the network to act as a gateway/repeater and extend the network’s range. The internet connection can be repeated as many times as you want. So the range can be limitless as long as the signal strength between devices is good enough. Since only one device connects to the WiFi AP the network is not overloaded. Another advantage is that the network can be made robust by allowing the network to reroute itself when a device stops working or when there is some kind of local interference. Last but not least is that it is completely free since it requires no additional hardware, only a change in firmware.
Of course, there are downsides such as lower bandwidth and higher latency, but for many IoT applications, those are acceptable.
Concept of ESP32 WiFi mesh network
ESP32 devices are very popular for IoT applications given it’s integrated WiFi and BLE radios, IO capabilities, and powerful processor. Espressif has implemented a WiFi mesh network (they also have Bluetooth mesh).
According to Espressif:
“ESP-WIFI-MESH is a networking protocol built atop the Wi-Fi protocol. ESP-WIFI-MESH allows numerous devices (henceforth referred to as nodes) spread over a large physical area (both indoors and outdoors) to be interconnected under a single WLAN (Wireless Local-Area Network). ESP-WIFI-MESH is self-organizing and self-healing meaning the network can be built and maintained autonomously.”
The network gives all nodes access to the internet. It also allows communication between nodes. Messages can be sent to specific nodes, but also to all nodes (multicasting) or to a select group of nodes (multicasting with group control). This allows interaction between nodes.
The network has a tree topology. There is one node that is connected to the WiFi AP: the root node. Every node can have 1 or more nodes connected to it, called child nodes. There is a configurable maximum number of child nodes per node and a configurable maximum number of layers. The nodes in the last layer cannot have child nodes and are called leaf nodes. It is important to note that the term leaf node can be misleading as nodes which do not have child nodes but are not in the maximum configured layer, are not leaf nodes. The network uses the signal strength (RSSI) instead of the distance to determine the topology of the network and can reroute itself when there is an offline node or signal loss.
Running WiFi mesh
We’ve created an example for you to get started with WiFi mesh:
https://github.com/wizzdev-pl/wifi-mesh
Pushing the boot button on an ESP32 devkit triggers it to send a message through the mesh network to other nodes and publish it to an MQTT broker.
Our setup used a mixture of ESP32 and ESP32C3 devkits. The devices were placed on a desk near a router and connected to a PC for power and debugging. The PC had mosquitto client running and was subscribed to the topics. One device was powered by a power bank so we could do a range test. We used the android app MQTIZER as an MQTT client to debug the MQTT message while doing a range test. We were able to go outside the office, 40 meters from the setup before the connection dropped.
Please also check rest of out articles on WizzDev Blog!
Sources
FAQ
1. What is a mesh network?
A self-healing network where devices act as repeaters, extending range and reducing congestion.
2. Why use ESP32 for IoT?
It’s affordable, integrates WiFi/Bluetooth, and supports mesh networking.
3. Benefits of a mesh network?
Extended range, resilience, reduced congestion, and no extra hardware costs.
4. How can I start with ESP32 mesh?
Use our GitHub example to set up and test your network.