Wiznet makers

matthew

Published May 29, 2025 ©

84 UCC

8 WCC

30 VAR

0 Contests

0 Followers

0 Following

Original Link

ESP32 AsyncMQTT_ESP32 MQTT DHT22

A real-time IoT system using ESP32, DHT22, MQTT, and Node-RED to monitor temperature and humidity, visualize data, store it in SQLite, and send LINE alerts.

COMPONENTS
PROJECT DESCRIPTION

Hardware Components

ESP32 Dev Board – Serves as the main microcontroller, responsible for handling sensor readings and MQTT communication.

DHT22 Sensor – A digital sensor used to measure temperature and humidity.

W5500 Ethernet Module (optional) – Enables wired Ethernet connectivity for environments requiring stable network performance.

LAN8720 / ENC28J60 Modules (optional) – Other supported Ethernet options for versatile network integration.

USB Cable – Used to power and program the ESP32 board.

Breadboard & Jumper Wires (for physical builds) – Used for prototyping sensor and module connections.


Software, Applications & Online Services

Wokwi Simulator – Web-based ESP32 simulation platform used to test and demonstrate the system without physical hardware.

Arduino IDE – Development environment used to write, compile, and upload code to the ESP32.

AsyncMQTT_ESP32 Library – Provides MQTT communication over both Wi-Fi and Ethernet for ESP32.

ArduinoJson Library – Handles JSON serialization of sensor data.

Node-RED – A flow-based visual programming tool used to create dashboards, automate database interactions, and visualize live data.

Mosquitto Public MQTT Brokertest.mosquitto.org is used for MQTT message publishing and subscribing.

SQLite – Lightweight local database used to store environmental sensor records.

LINE Notify API – Sends real-time notifications directly to the LINE messaging app.

 

Building a Real-Time Temperature & Humidity Monitoring System Using ESP32, DHT22, MQTT, and Node-RED

This project showcases a practical implementation of an IoT-based temperature and humidity monitoring system, developed using the ESP32 microcontroller, DHT22 sensor, MQTT protocol, and Node-RED dashboard. Designed in the Wokwi simulator environment, it serves as a great demonstration of how embedded systems can interact with cloud-based services and user interfaces in real time.


Capturing and Transmitting Environmental Data with ESP32 and DHT22

The core of the system is the ESP32, which periodically reads temperature and humidity values from a connected DHT22 sensor. The sensor data is formatted into a JSON object and published every 2.5 seconds to the MQTT topic alex9ufo/esp32/dht/temphumi. Communication is handled using the AsyncMQTT_ESP32 library, and the system is designed to auto-reconnect using FreeRTOS software timers in case of network disconnections.

Each payload includes a serialized JSON string with both temperature and humidity values. If an error occurs during data reading (e.g., a sensor failure), the system outputs a corresponding error message to the serial monitor for debugging purposes.


Data Visualization and Storage Using Node-RED

On the Node-RED side, the project implements a comprehensive dashboard and data management system:

An MQTT input node subscribes to the topic alex9ufo/esp32/dht/temphumi to receive real-time sensor data.

The received values are displayed on two dashboard gauges, representing temperature and humidity respectively.

Incoming data is parsed and stored in a SQLite database table named DHT22STATUS, which holds temperature, humidity, date, and time entries.

Users can interact with the database through the Node-RED UI, with features such as:

Creating and deleting the database table.

Viewing all or specific entries.

Editing or deleting individual entries.

Displaying the latest 50 entries in a table view.

All database operations are dynamically triggered using Function nodes, which construct and execute SQL queries based on user input.


LINE Notify Integration for Remote Monitoring

An additional feature includes LINE Notify integration, enabling remote alerts via LINE messages. When triggered, the system formats a message such as “---ESP32 Data Received--- Temperature XX℃ , Humidity XX%” and sends it to the configured LINE channel using the Notify API. This enables instant awareness of environmental changes without needing to access the dashboard directly.


System Architecture Overview

ComponentDescription
SensorDHT22 (Temperature & Humidity)
MicrocontrollerESP32 (Simulated using Wokwi)
Communication ProtocolMQTT (Broker: test.mosquitto.org)
Libraries UsedAsyncMQTT_ESP32, ArduinoJson, Adafruit DHT Library
DatabaseSQLite (Table: DHT22STATUS)
Dashboard ToolNode-RED (Real-time visualization with gauges and tables)
Notification ServiceLINE Notify (For remote environmental alerts)

Conclusion and Future Enhancements

This project effectively demonstrates how to combine ESP32-based sensor monitoring with cloud communication protocols and real-time dashboards. It is an ideal project for beginners and intermediate makers to understand the fundamentals of IoT system design, from sensor integration to cloud data handling.

Potential future improvements could include:

Support for Ethernet (LAN8720 or W5500) communication instead of Wi-Fi.

Cloud data synchronization with platforms like Firebase or Google Sheets.

Advanced analytics or machine learning for trend prediction.

Triggered alerts for abnormal readings (e.g., extreme temperatures).

Overall, this system is a powerful, scalable, and educational IoT project that can serve as a solid foundation for more advanced environmental monitoring solutions.

Documents
Comments Write