Main Content

Multiple IoT device communication on ESP32

The goal behind the project is to set a baseline example of how to setup communication between multiple IoT devices using MQTT protocol

Internet of Things (IoT) has seen unprecedented change over the past few years changing the way people live and work. IoT encourages companies to rethink the ways they approach their businesses and gives them the tools to improve their business strategies. There are numerous real-world applications of the internet of things, ranging from consumer IoT and enterprise IoT to manufacturing and industrial IoT (IIoT). IoT applications span numerous verticals, including automotive, telecom and energy. One area that will be crucial going forward is the ability to understand how IoT and IIoT will eventually merge. In the below example we try demonstrating one such example where we try to put together the world of IoT and IIoT.

ESP32 dev kit
ESP32 is a low-cost, low-power system on a chip (SoC) series with Wi-Fi & dual-mode Bluetooth capabilities. It comprises of a dual core or a single core Tensilica Xtensa LX6 microprocessor with a clock rate of up to 240 MHz with integrated Wi-Fi and dual-mode Bluetooth.

Wi-Fi: 802.11 b/g/n/e/i (802.11n @ 2.4 GHz up to 150 Mbit/s)
Bluetooth: v4.2 BR/EDR and Bluetooth Low Energy (BLE)
Flash: 4 MB
SRAM: 520 KB
Ref: The Internet of Things with ESP32

Micro Python is a lean and efficient implementation of Python3 which includes a small subset of Python standard library and is optimized to run on micro controllers. It consists of an interactive prompt (REPL) to execute commands immediately. It also can import and run scripts from built in filesystem. In addition to a selection of core Python libraries it also implements modules such as “machine” for accessing low-level hardware. MicroPython runs on a variety of systems and hardware platforms.

MQTT (Message Queue Telemetry Transport)
For IoT devices connecting to internet is a crucial aspect of their functionality. This allows the devices to communicate with each other and the backend services. MQTT, which is built on top of the TCP/IP stack is a light weight, open and a simple messaging protocol for small sensors and mobile devices. It is easy to implement and makes it ideal for use in many situations, especially in resource constraint environments where a “small code footprint” is required such as for communication in Internet of Things (IoT). MQTT protocol has become a standard for IoT communications and can run on SSL/TLS, which is a secure protocol on top of TCP/IP to ensure that all data communication between the devices is encrypted and secure. MQTT is a publish-subscribe network protocol which defines two types of entities: a message broker and multiple clients. The broker is a server which receives all the messages from the clients and routes the messages to the corresponding destination clients. On the other hand, the client can be anything from an IoT device to machine learning model that makes predictions based on this data.

The main advantages of MQTT broker are:

1. Use of the publish/subscribe message pattern which provides one-to-many message distribution and decoupling of applications.
2. Eliminates vulnerable and insecure client connections.
3. Can easily scale from a single device to thousands.
4. Manages and tracks all client connection states, including security credentials and certificates.
5. Reduced network strain without compromising the security (cellular or satellite network)”

Link to article