Introduction
Temperature and humidity monitoring is a cornerstone of industrial IoT — from server rooms and greenhouses to pharmaceutical storage and smart warehouses. The DHT22 and DHT11 sensors are among the most popular choices for such tasks because they’re cheap, widely available, and easy to interface with microcontrollers like ESP32 or Arduino. But raw sensor data is just numbers. The real value comes when you can analyze trends, trigger alerts, and automate responses — which is exactly what an AI agent like ASI Biont can do.
In this article, we’ll show you how to connect a DHT22 sensor to ASI Biont using MQTT and an ESP32, and how the AI agent can turn that data into actionable intelligence. No dashboards, no 'add device' buttons — just a conversation with the AI that writes all the code for you.
Why Connect a DHT22 to an AI Agent?
A standalone DHT22 logger writes to an SD card or sends data to a cloud dashboard. But an AI agent goes further:
- Trend analysis: Detect gradual humidity drifts that precede mold or equipment failure.
- Anomaly detection: Spot sudden temperature spikes caused by an open door or AC failure.
- Automated actions: Send a Telegram alert when a threshold is crossed, or trigger a relay to turn on a dehumidifier.
- Contextual reasoning: The AI can correlate sensor data with external factors (weather API, time of day, production schedule) to make smarter decisions.
According to a 2025 report by IoT Analytics, 73% of industrial IoT projects now include some form of edge AI or cloud AI for data processing. ASI Biont makes this accessible without writing a single line of integration code yourself.
Which Connection Method and Why?
For DHT22/DHT11 sensors, the most practical connection method is MQTT via an ESP32. Here’s why:
| Method | Pros | Cons | Best for |
|---|---|---|---|
| MQTT (ESP32) | Low latency, simple code, works over WiFi, bi-directional | Requires MQTT broker (Mosquitto) | Remote sensors, multi-sensor networks |
| COM port via Hardware Bridge | Direct serial read, no WiFi needed | Cable length limit, local PC required | Arduino wired setups, lab experiments |
| SSH (Raspberry Pi) | Full GPIO control, can run complex local scripts | Requires Linux knowledge, power hungry for simple sensors | Multi-sensor hubs with cameras |
| HTTP API | Standard REST, easy to debug | Higher overhead, polling required | Smart plugs, cloud-connected devices |
For a warehouse or server room, MQTT is ideal because sensors are distributed, and the broker can handle many devices. The AI agent subscribes to the sensor’s MQTT topic, reads temperature and humidity, and acts on it.
Use Case: Smart Warehouse Temperature & Humidity Monitoring
Scenario: A pharmaceutical warehouse stores vaccines at 2–8°C. If temperature exceeds 8°C for more than 10 minutes, the AI must alert the manager and log the event.
Hardware:
- ESP32 (e.g., ESP32 DevKit V1)
- DHT22 sensor (AM2302)
- Breadboard and jumper wires
- MQTT broker (Mosquitto running on a Raspberry Pi or cloud)
Wiring Diagram:
| DHT22 Pin | ESP32 Pin |
|---|---|
| VCC (pin 1) | 3.3V |
| DATA (pin 2) | GPIO4 (D4) |
| GND (pin 4) | GND |
| (NC, pin 3) | - |
A 10kΩ pull-up resistor between VCC and DATA is recommended for stable readings.
MicroPython Code for ESP32:
from machine import Pin
import dht
import time
import network
from umqtt.simple import MQTTClient
# WiFi credentials
WIFI_SSID = 'YourSSID'
WIFI_PASS = 'YourPassword'
# MQTT broker settings
MQTT_BROKER = '192.168.1.100' # IP of your Mosquitto broker
MQTT_TOPIC = b'sensors/warehouse1/dht22'
CLIENT_ID = 'esp32_dht22'
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASS)
while not wlan.isconnected():
time.sleep(1)
print('WiFi connected')
def read_sensor():
sensor = dht.DHT22(Pin(4))
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
return temp, hum
connect_wifi()
client = MQTTClient(CLIENT_ID, MQTT_BROKER)
client.connect()
while True:
try:
temp, hum = read_sensor()
msg = f'{{"temp": {temp}, "hum": {hum}}}'
client.publish(MQTT_TOPIC, msg)
print(f'Published: {msg}')
time.sleep(60) # Send every minute
except Exception as e:
print('Error:', e)
time.sleep(5)
How ASI Biont Connects and Automates
Once the ESP32 is publishing data to the MQTT broker, you can connect ASI Biont to that broker by simply describing the setup in the chat:
User: “Connect to MQTT broker at 192.168.1.100:1883, subscribe to topic sensors/warehouse1/dht22, and monitor temperature. If it exceeds 8°C for more than 10 minutes, send a Telegram alert to @warehouse_manager.”
The AI agent will generate and execute a Python script using paho-mqtt in its sandbox environment (execute_python). Here’s what the script looks like:
import paho.mqtt.client as mqtt
import time
import json
import requests
TELEGRAM_BOT_TOKEN = 'YOUR_BOT_TOKEN'
TELEGRAM_CHAT_ID = '@warehouse_manager'
THRESHOLD = 8.0
ALERT_DELAY = 600 # 10 minutes in seconds
last_alert_time = 0
consecutive_exceed = 0
def on_message(client, userdata, msg):
global last_alert_time, consecutive_exceed
data = json.loads(msg.payload.decode())
temp = data['temp']
print(f'Received temp: {temp}')
if temp > THRESHOLD:
consecutive_exceed += 60 # assuming 60s interval
if consecutive_exceed >= ALERT_DELAY and (time.time() - last_alert_time) > 300:
# Send Telegram alert
text = f'⚠️ ALERT: Temperature {temp}°C exceeded {THRESHOLD}°C for {consecutive_exceed//60} minutes!'
requests.post(
f'https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage',
json={'chat_id': TELEGRAM_CHAT_ID, 'text': text}
)
last_alert_time = time.time()
else:
consecutive_exceed = 0
client = mqtt.Client()
client.on_message = on_message
client.connect('192.168.1.100', 1883, 60)
client.subscribe('sensors/warehouse1/dht22')
client.loop_forever()
Important: The AI runs this script in a cloud sandbox with a 30-second timeout, so for long-running MQTT listeners, the AI uses the industrial_command tool with the broker:// protocol to set up a persistent subscription. The script above is a simplified example to illustrate the logic.
Step-by-Step Integration Walkthrough
- Flash your ESP32 with the MicroPython script above (use Thonny or esptool.py).
- Start Mosquitto on your broker machine:
mosquitto -c /etc/mosquitto/mosquitto.conf. - Open ASI Biont chat at asibiont.com and describe your integration.
- The AI asks for details: broker IP, topic, threshold, Telegram credentials.
- The AI writes and executes the integration code — you see logs in real-time.
- Test it: Heat the sensor with your hand. The AI should detect the rise and send an alert.
Why This Beats Traditional Dashboards
Traditional IoT platforms require you to:
- Set up a device registry
- Configure data pipelines
- Write alert rules in a UI
- Deploy integrations
With ASI Biont, you just talk to the AI. It handles all the code, routing, and logic. The same AI that monitors temperature can also control relays, read other sensors, and even generate reports — all through conversation.
Advanced Scenarios
| Scenario | How ASI Biont Handles It |
|---|---|
| Multi-zone warehouse | Subscribe to multiple topics (warehouse1/zone1, warehouse1/zone2) and compare zones |
| Predictive maintenance | Collect 30 days of data, train a simple linear regression model using scikit-learn in sandbox, predict when AC will fail |
| Cross-correlation | Fetch weather data via HTTP API and compare indoor vs outdoor humidity trends |
| Automated response | Publish to MQTT topic actuators/dehumidifier to turn on a relay when humidity > 70% |
For example, to add a dehumidifier control, just tell the AI: “If humidity exceeds 70%, publish ‘ON’ to topic actuators/dehumidifier.” The AI will modify the script to add a publish call.
Real-World Testimonials
“We connected 12 DHT22 sensors in our cold storage facility to ASI Biont in under 30 minutes. The AI spotted a failing compressor 3 days before it broke — saved us $4,000 in spoiled inventory.” — Alex K., logistics manager
“I’m not a programmer. I just described my greenhouse setup to the AI, and it wrote the MQTT bridge, alerting, and even a weekly report script. Unbelievable.” — Maria L., hobbyist farmer
Conclusion
Integrating a DHT22 or DHT11 temperature/humidity sensor with ASI Biont transforms a simple data logger into an intelligent environmental watchdog. Using MQTT and an ESP32, you get real-time monitoring, AI-driven alerts, and automated responses — all configured through natural conversation.
The best part? You don’t need to wait for platform updates or write complex integration code. ASI Biont connects to any device via execute_python — the AI itself generates the code using pyserial, paramiko, paho-mqtt, pymodbus, aiohttp, or opcua-asyncio. Just describe your device, connection parameters (port, IP, baud rate, API key), and the AI handles the rest.
Ready to try it? Go to asibiont.com, start a chat, and tell the AI: “Connect my DHT22 sensor via MQTT and alert me if temperature exceeds 30°C.” See how fast real AI integration happens.
Comments