Why Connect a Weather Station to an AI Agent?
Weather stations are everywhere—backyards, farms, greenhouses, and industrial sites. But raw data from temperature, humidity, and pressure sensors is useless without analysis and action. An AI agent like ASI Biont turns that data into intelligent decisions: send a Telegram alert when frost is coming, log readings to a database, or trigger a smart home heater.
This guide shows how to connect a weather station built on an ESP32 with a DHT22/BMP180 sensor to ASI Biont using MQTT. No dashboard panels, no code writing—just describe your setup in chat, and the AI writes the integration for you.
Which Connection Method and Why?
For an ESP32 weather station, MQTT is the best choice:
- Lightweight protocol – ESP32 can publish sensor readings every few seconds with minimal power.
- Cloud-friendly – MQTT broker (like Mosquitto or HiveMQ) sits between the device and ASI Biont, handling disconnections.
- Proven in IoT – Over 60% of commercial IoT deployments use MQTT (source: IoT Analytics 2025).
ASI Biont connects to any MQTT broker via the industrial_command tool or by writing a Python script with paho-mqtt in the execute_python sandbox. The AI subscribes to your sensor topics, analyzes trends, and publishes commands back.
Concrete Use Case: ESP32 + DHT22/BMP180 → ASI Biont → Telegram Alerts
The Setup
| Component | Model/Protocol | Role |
|---|---|---|
| Microcontroller | ESP32 DevKit | WiFi + MQTT publisher |
| Temperature/Humidity | DHT22 | ±0.5°C, ±2% RH |
| Barometric Pressure | BMP180 | ±1 hPa |
| MQTT Broker | Mosquitto (on a Raspberry Pi or cloud) | Message queue |
| AI Agent | ASI Biont | Data analysis + Telegram |
How It Works
- ESP32 reads sensors every 10 seconds and publishes JSON to MQTT topic
weather/station1/data. - ASI Biont subscribes to that topic via a Python script using
paho-mqtt. - AI analyzes the data: if temperature drops below 5°C or humidity exceeds 85%, it sends a Telegram alert.
- User gets notified on Telegram within seconds.
Step-by-Step Integration
1. Flash the ESP32 with MicroPython
Upload this main.py to your ESP32 (using Thonny or ampy):
import network
import time
import json
from machine import Pin, I2C
import dht
import bmp180
from umqtt.simple import MQTTClient
# WiFi credentials
SSID = "your_wifi"
PASSWORD = "your_password"
# MQTT broker (replace with your broker IP)
MQTT_BROKER = "192.168.1.100"
TOPIC = "weather/station1/data"
# Sensors
dht_sensor = dht.DHT22(Pin(4))
i2c = I2C(scl=Pin(22), sda=Pin(21))
bmp = bmp180.BMP180(i2c)
# Connect WiFi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
while not wlan.isconnected():
time.sleep(1)
# Connect MQTT
client = MQTTClient("esp32_weather", MQTT_BROKER)
client.connect()
while True:
dht_sensor.measure()
temp = dht_sensor.temperature()
hum = dht_sensor.humidity()
pressure = bmp.pressure / 100 # convert to hPa
payload = json.dumps({
"temperature": temp,
"humidity": hum,
"pressure": pressure
})
client.publish(TOPIC, payload)
time.sleep(10)
2. Connect ASI Biont to the MQTT Broker
In the ASI Biont chat, describe your setup:
"Connect to MQTT broker at 192.168.1.100:1883, subscribe to topic weather/station1/data. If temperature < 5°C or humidity > 85%, send a Telegram alert to my chat."
ASI Biont will generate and run this Python script in the sandbox:
import paho.mqtt.client as mqtt
import json
import asyncio
from telegram import Bot
TELEGRAM_TOKEN = "your_token"
CHAT_ID = "your_chat_id"
def on_message(client, userdata, msg):
data = json.loads(msg.payload)
temp = data["temperature"]
hum = data["humidity"]
if temp < 5 or hum > 85:
alert = f"⚠️ Weather alert: Temp={temp}°C, Humidity={hum}%"
asyncio.run(Bot(TELEGRAM_TOKEN).send_message(chat_id=CHAT_ID, text=alert))
mqtt_client = mqtt.Client()
mqtt_client.on_message = on_message
mqtt_client.connect("192.168.1.100", 1883, 60)
mqtt_client.subscribe("weather/station1/data")
mqtt_client.loop_forever()
3. Receive Alerts on Telegram
When temperature drops to 4°C, you get:
⚠️ Weather alert: Temp=4.2°C, Humidity=82%
Why This Beats Manual Coding
- Zero boilerplate – No need to write MQTT subscribe loops, JSON parsers, or Telegram APIs. ASI Biont generates it in seconds.
- Any MQTT device – Works with any ESP32, Raspberry Pi, or industrial sensor that publishes MQTT. Just change the topic.
- Extensible – Ask the AI to log data to a PostgreSQL database, or control a smart plug when temperature exceeds 30°C.
Real-World Pitfalls to Avoid
- Broker security – Never expose an unsecured MQTT broker to the internet. Use TLS and authentication.
- ESP32 power – If running on batteries, increase publish interval to 60 seconds and use deep sleep.
- Sandbox timeout – The
execute_pythonsandbox has a 30-second timeout. For long-running MQTT loops, useindustrial_commandwithpublishcommand instead.
Conclusion
Connecting a weather station to ASI Biont takes 10 minutes: flash the ESP32, tell the AI your broker details, and start receiving intelligent alerts. No dashboards, no manual code—just a natural conversation.
Try it yourself at asibiont.com. Describe your device, and let the AI handle the rest.
Comments