---
title: "ESP32 AsyncMQTT_ESP32 MQTT DHT22"
url: "https://maker.wiznet.io/matthew/projects/esp32-asyncmqtt-esp32-mqtt-dht22/"
markdown_url: "https://maker.wiznet.io/matthew/projects/esp32-asyncmqtt-esp32-mqtt-dht22/md"
type: "UCC: User Created Content"
author: "alex9ufo"
author_url: "https://alex9ufoexploer.blogspot.com/2025/01/"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "alex9ufo"
original_url: "https://alex9ufoexploer.blogspot.com/2025/01/"
published: "2025-05-29"
language: "en"
likes: 0
views: 1902
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# 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.

Original author: alex9ufo (source: https://alex9ufoexploer.blogspot.com/2025/01/)

## Article

## **Hardware ComponentsESP32 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 ServicesWokwi 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 Broker** – `test.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**

| Component | Description |
| --- | --- |
| **Sensor** | DHT22 (Temperature & Humidity) |
| **Microcontroller** | ESP32 (Simulated using Wokwi) |
| **Communication Protocol** | MQTT (Broker: `test.mosquitto.org`) |
| **Libraries Used** | AsyncMQTT_ESP32, ArduinoJson, Adafruit DHT Library |
| **Database** | SQLite (Table: DHT22STATUS) |
| **Dashboard Tool** | Node-RED (Real-time visualization with gauges and tables) |
| **Notification Service** | LINE 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.**

---

Source: https://maker.wiznet.io/matthew/projects/esp32-asyncmqtt-esp32-mqtt-dht22/
