WiFi and MQTT on the ESP32
Short Summary
This project explores setting up WiFi and MQTT on the ESP32 as the foundation for edge connectivity in IoT and IIoT applications. By combining C++ firmware, a HiveMQ broker, and Python-based testing, the system demonstrates seamless communication between devices and the cloud.
Problem
IoT and IIoT devices often struggle with lightweight, reliable communication. Proprietary solutions can be expensive, and many lack flexibility for quick prototyping and integration with existing infrastructure. A standardized and open approach is needed to handle device-to-cloud messaging efficiently.
Solution
Using an ESP32 microcontroller, the project establishes a communication layer with:
- WiFi connectivity using the ESP32’s onboard module and WiFi.hin PlatformIO (C++).
- MQTT messaging implemented via the Paho MQTT client for reliable pub/sub communication.
- HiveMQ broker to handle message routing during testing.
- LED visualization on the ESP32 board to respond to MQTT messages in real-time.
- Python test script using Paho for sending commands from a terminal prompt, enabling fast and flexible testing without third-party tools.
How It Works
WiFi Connection
The ESP32 connects to a local WiFi network using credentials stored in firmware.
MQTT Setup
Paho MQTT client initializes with the HiveMQ broker, subscribing to relevant topics and publishing device status.
Edge Communication
Commands from the Python script (or another MQTT client) are routed through HiveMQ to the ESP32.
Visualization
Incoming messages trigger LEDs on the ESP32, providing immediate feedback on communication status.
Software Methodology Flowchart
Key Features
- Lightweight, reliable MQTT messaging
- Real-time feedback via LEDs
- Python test client for rapid validation
- C++ firmware built on PlatformIO
- Open, flexible architecture for IoT/IIoT prototyping
Hardware & Software Stack
Hardware
- ESP32 microcontroller with onboard WiFi
- LEDs for MQTT-driven feedback
Software
- C++ firmware (PlatformIO)
- WiFi.hfor wireless connectivity
- Paho MQTT client for pub/sub
- HiveMQ broker for message routing
- Python script for MQTT testing via terminal
Evaluation & Testing
- Verified WiFi connection stability on ESP32
- Published and subscribed to multiple topics on HiveMQ broker
- Tested LED visualization with live MQTT messages
- Validated bidirectional communication using Python terminal script
Conclusion
This project demonstrates how the ESP32 can serve as a low-cost edge device for IoT and IIoT communication. With WiFi, MQTT, HiveMQ, and a Python test client, the system provides a flexible and scalable foundation for connected applications.
Future work will expand functionality.