ESP32 Meets ASI Biont: AI-Driven Automation for IoT and Industrial Edge

Introduction

The ESP32 is arguably the most versatile microcontroller for IoT projects—dual-core processor, built-in Wi-Fi and Bluetooth, deep sleep modes, and a rich peripheral set (SPI, I2C, UART, CAN, ADC, DAC). But its real power is unlocked when you pair it with an AI agent that can write, debug, and execute integration code on the fly. This article is a practical guide to connecting an ESP32 to ASI Biont, an AI agent that automates industrial and IoT tasks through natural language conversation. No dashboards, no buttons—just you, the AI, and your hardware.

Why Connect ESP32 to an AI Agent?

Manual coding for every sensor, actuator, or protocol variant is tedious. The ESP32 ecosystem spans Arduino IDE, ESP-IDF, MicroPython, and CircuitPython, each with its own libraries. ASI Biont eliminates this friction: you describe your hardware setup in plain English, and the AI generates the integration code using real connection methods. You can automate data logging, remote control, anomaly detection, and alerting without writing a single line of boilerplate.

Connection Methods Supported by ASI Biont

ASI Biont connects to ESP32 through several proven channels:

Method Protocol Use Case
MQTT paho-mqtt IoT sensor data, smart home, cloud messaging
COM Port (UART) Hardware Bridge (bridge.py) Serial debug, Modbus RTU, direct UART control
HTTP API aiohttp REST endpoints on ESP32 (e.g., ESPAsyncWebServer)
WebSocket websockets Real-time bidirectional communication
CoAP aiocoap Constrained IoT devices, low-bandwidth
SSH paramiko ESP32 running Linux (ESP32-S3 + ESP-IDF SSH server)

For this guide, we focus on MQTT—the most universal and reliable method for ESP32 cloud integration. We'll also cover COM port via Hardware Bridge for scenarios where Wi-Fi is unavailable.

Real-World Use Case: Environmental Monitoring with ESP32 + DHT22

The Problem

A small greenhouse needs 24/7 temperature and humidity monitoring. If the temperature exceeds 35°C or drops below 10°C, the grower must be alerted immediately. The ESP32 sits in a corner with a DHT22 sensor, powered by a 5V USB cable. The grower wants to receive Telegram alerts and log data to a CSV file for analysis.

The Solution: ASI Biont + MQTT

The grower describes the setup in the ASI Biont chat: "Connect to ESP32 via MQTT broker at 192.168.1.100:1883, topic 'greenhouse/sensor'. Read temperature and humidity, alert me on Telegram if temperature is out of range, and log to a CSV file."

ASI Biont generates and executes the following Python script in its sandbox (execute_python):

import paho.mqtt.client as mqtt
import json
import csv
from datetime import datetime

TELEGRAM_BOT_TOKEN = 'your_bot_token'
TELEGRAM_CHAT_ID = 'your_chat_id'

def on_message(client, userdata, msg):
    data = json.loads(msg.payload.decode())
    temp = data['temperature']
    hum = data['humidity']
    timestamp = datetime.now().isoformat()

    # Log to CSV
    with open('greenhouse_log.csv', 'a', newline='') as f:
        writer = csv.writer(f)
        writer.writerow([timestamp, temp, hum])

    # Alert if out of range
    if temp > 35 or temp < 10:
        alert_text = f"Alert: Temp {temp}°C at {timestamp}"
        # Send Telegram (simplified, uses requests)
        import requests
        url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
        requests.post(url, json={'chat_id': TELEGRAM_CHAT_ID, 'text': alert_text})

client = mqtt.Client()
client.on_message = on_message
client.connect('192.168.1.100', 1883, 60)
client.subscribe('greenhouse/sensor')
client.loop_forever()

The AI then asks the user to configure MQTT publishing on the ESP32 side. The user uploads a simple MicroPython script to the ESP32:

import network
import time
import dht
from machine import Pin
from umqtt.simple import MQTTClient
import json

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect('SSID', 'PASSWORD')
while not wifi.isconnected():
    time.sleep(1)

sensor = dht.DHT22(Pin(4))
client = MQTTClient('esp32', '192.168.1.100')
client.connect()

while True:
    sensor.measure()
    payload = json.dumps({'temperature': sensor.temperature(),
                          'humidity': sensor.humidity()})
    client.publish('greenhouse/sensor', payload)
    time.sleep(60)

Result

The AI agent now continuously monitors the greenhouse. When the temperature spikes, the grower receives a Telegram message within seconds. Data is logged for later analysis. All integration code was written by the AI in response to a natural language description.

Alternative: COM Port Connection via Hardware Bridge

If Wi-Fi is unreliable, use the Hardware Bridge. The user runs bridge.py on a PC connected to the ESP32 via USB (COM3, 115200 baud). The AI sends commands through the industrial_command tool:

industrial_command(
    protocol='serial://',
    command='serial_write_and_read',
    params={
        'data': '524541445f54454d500a',  # hex for "READ_TEMP\n"
        'port': 'COM3',
        'baud': 115200
    }
)

The bridge writes the command to the ESP32 UART, reads the response (e.g., "25.3°C"), and returns it to the AI. The AI can then trigger alerts, log data, or control actuators (e.g., "TURN_ON_FAN").

Advanced Scenario: Predictive Maintenance with ESP32 + Vibration Sensor

A factory conveyor belt has an ESP32 connected to an ADXL345 accelerometer via I2C. The AI subscribes to MQTT topics vibration/x, vibration/y, vibration/z. It computes the RMS acceleration over a sliding window of 100 samples. If the RMS exceeds a configurable threshold (e.g., 2.0 m/s²), the AI sends a maintenance alert and logs the event to a PostgreSQL database (using psycopg2 in the sandbox).

import paho.mqtt.client as mqtt
import json
from collections import deque
import numpy as np

window = deque(maxlen=100)

def on_message(client, userdata, msg):
    data = json.loads(msg.payload.decode())
    window.append(data['z'])
    if len(window) == window.maxlen:
        rms = np.sqrt(np.mean(np.array(list(window))**2))
        if rms > 2.0:
            # Alert and log
            print(f"Vibration anomaly: RMS={rms:.2f}")
            # psycopg2 insert here

client = mqtt.Client()
client.on_message = on_message
client.connect('192.168.1.100', 1883)
client.subscribe('vibration/#')
client.loop_forever()

The user simply describes the sensor and threshold in the chat; the AI generates the entire pipeline.

Benefits of AI-Powered Integration

  • Zero boilerplate: Describe your hardware, and the AI writes the integration code.
  • Multi-protocol: MQTT, serial, HTTP, CoAP, WebSocket—the AI picks the best method.
  • Real-time adaptation: Change thresholds, add alerts, or switch brokers by asking the AI.
  • No vendor lock-in: Use any ESP32 board, any sensor, any broker.

Conclusion

ESP32 is a powerful IoT platform, but its true potential emerges when paired with an AI agent that automates the integration itself. ASI Biont connects to your ESP32 via MQTT, serial, or other protocols—all through natural language conversation. No dashboards, no tedious configuration. Just describe what you need, and the AI delivers a production-ready solution in seconds.

Ready to automate your ESP32 project? Try it on asibiont.com.

← All posts

Comments