Introduction
Imagine deploying 30 temperature sensors across a greenhouse, 10 motion detectors in a warehouse, and a dozen relay switches for irrigation — all talking to each other without a single Wi-Fi router. That’s the promise of ESP-NOW, Espressif’s connectionless peer-to-peer protocol for ESP32 and ESP8266 microcontrollers. Unlike standard Wi-Fi, which requires an access point and suffers from congestion as device count climbs, ESP-NOW operates in the 2.4 GHz ISM band with direct device-to-device communication. Latency drops to 2–3 ms, and you can build a mesh of up to 20 devices per ESP32 (with relays, hundreds).
But raw ESP-NOW has a problem: it’s a fire-and-forget protocol. There’s no central brain to collect data, log trends, or make decisions. That’s where ASI Biont enters. ASI Biont is an AI agent that connects to any device — including an ESP32 ESP-NOW gateway — via a COM port, MQTT, or HTTP API. In this guide, I’ll show you how to bridge an ESP-NOW sensor network to ASI Biont using an ESP32 gateway connected over a serial (COM) port via the Hardware Bridge. The AI agent then reads sensor data, sends commands to actuators, and automates the entire mesh — all through a chat conversation.
The Problem: Wi-Fi Isn’t Built for Dense IoT
Standard Wi-Fi (IEEE 802.11) was designed for high-bandwidth client-server traffic — laptops streaming video, phones browsing the web. When you connect 50 ESP32 temperature sensors to a single router, several things happen:
- The router’s association table fills up. Most consumer routers cap out at 20–30 simultaneous clients.
- Beacon intervals and CSMA/CA collisions increase latency. A sensor reading that should take 10 ms can balloon to 500 ms.
- Power consumption rises because each sensor must maintain a TCP/IP stack and periodic re-association.
ESP-NOW sidesteps all this. It uses a lightweight data frame (no TCP/UDP headers), no handshake, and no router. Each ESP32 stores a peer list of up to 20 MAC addresses and sends data frames directly. For larger networks, you daisy-chain relay nodes to form a mesh.
According to Espressif’s official documentation (ESP-NOW User Guide, 2023), the protocol achieves a round-trip time of 2–3 ms for a single hop, with a maximum payload of 250 bytes per packet. That’s ideal for sensor readings — temperature, humidity, motion flags, or relay states.
The Solution: ESP32 Gateway + ASI Biont via Hardware Bridge
The architecture is simple:
- Sensor nodes (ESP32 with DHT22, PIR, or relay) broadcast data via ESP-NOW.
- A gateway ESP32 receives all ESP-NOW packets. It is also connected to a PC via USB (COM port) running
bridge.py(the ASI Biont Hardware Bridge). - bridge.py connects to the ASI Biont cloud over WebSocket and exposes the COM port for read/write.
- The AI agent (ASI Biont) sends commands through the
industrial_commandtool, which routes them to the bridge. The bridge writes hex-encoded data to the COM port and reads the response.
Why this method? Because ESP-NOW itself has no IP stack — it’s a raw radio protocol. To reach the cloud, you need a gateway that can translate ESP-NOW frames into serial bytes. The COM port bridge is the simplest, most reliable way to do that without adding another Wi-Fi layer.
Wiring Diagram
[ESP32 Sensor Node 1] (Built-in antenna)
|
| ESP-NOW (2.4 GHz, no router)
|
[ESP32 Gateway] --- USB cable --- [PC/Laptop running bridge.py]
|
| WebSocket (secure tunnel)
|
[ASI Biont Cloud Server]
|
[AI Agent (Chat Interface)]
You don’t need any external hardware besides the ESP32 boards and a USB cable. The gateway ESP32 runs a sketch that initializes ESP-NOW, registers all known peers, and listens for incoming data. When a packet arrives, it prints the sender’s MAC address and payload to the Serial monitor (UART). The PC’s bridge.py reads that serial output and forwards it to the AI.
Step-by-Step: Connecting ESP-NOW to ASI Biont
1. Flash the ESP32 Gateway with a Serial Forwarder Sketch
Here is a complete Arduino sketch for the gateway. It initializes ESP-NOW in broadcast mode, listens for any incoming packet, and prints it as a formatted string to the serial port.
// ESP32 Gateway – ESP-NOW to Serial Bridge
#include <esp_now.h>
#include <WiFi.h>
// Structure to receive data
struct_message {
uint8_t mac[6];
float temperature;
float humidity;
bool motion;
};
struct_message incomingData;
void OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
memcpy(&incomingData, data, sizeof(incomingData));
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
info->src_addr[0], info->src_addr[1], info->src_addr[2],
info->src_addr[3], info->src_addr[4], info->src_addr[5]);
// Print to serial in a parseable format
Serial.printf("NODE:%s
|TEMP:%.2f|HUM:%.2f|MOTION:%d\n",
macStr, incomingData.temperature, incomingData.humidity, incomingData.motion);
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
return;
}
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
// Nothing to do – callback handles data
delay(1000);
}
Upload this to your gateway ESP32 using the Arduino IDE or PlatformIO. Make sure the baud rate matches what you’ll use in bridge.py (115200).
2. Run the ASI Biont Hardware Bridge
Download bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge). You need an API token. On your PC, open a terminal and run:
pip install pyserial requests websockets
python bridge.py --token=YOUR_API_TOKEN --ports=COM3 --baud 115200
Replace COM3 with your actual port (on Linux it’s /dev/ttyUSB0, on macOS /dev/cu.usbserial-XXXX). The bridge will connect to the ASI Biont cloud via WebSocket and open the COM port for reading and writing.
3. Tell the AI Agent to Read Sensor Data
Now, in the ASI Biont chat, you describe your setup. For example:
"I have an ESP32 gateway on COM3 at 115200 baud. It receives ESP-NOW data from sensor nodes. Read the serial stream and parse temperature, humidity, and motion values. If any temperature exceeds 35°C, send me a Telegram alert."
The AI agent will use the industrial_command tool with the serial_write_and_read command. It sends a hex-encoded command (e.g., data="524541440a" for "READ\n") and reads the response. But because the gateway is constantly streaming data (it prints a line every time a packet arrives), the AI can just listen.
Here’s the Python code the AI generates and runs inside its sandbox (using the industrial_command tool):
# This code is generated by ASI Biont AI and executed via execute_python
# It uses the industrial_command tool to communicate with the bridge
# Step 1: Tell the bridge to read from COM3 with a timeout
response = industrial_command(
protocol='serial',
command='serial_write_and_read',
data='', # empty – just read what's already in buffer
timeout=2000 # wait 2 seconds for data
)
# Step 2: Parse the response (multiple lines possible)
lines = response.split('\n')
alerts = []
for line in lines:
if line.startswith('NODE:'):
parts = line.split('|')
mac = parts[0].replace('NODE:', '')
temp = float(parts[1].replace('TEMP:', ''))
humidity = float(parts[2].replace('HUM:', ''))
motion = parts[3].replace('MOTION:', '') == '1'
# Check threshold
if temp > 35.0:
alerts.append(f"ALERT: Node {mac} temperature {temp}°C exceeds 35°C")
# Step 3: Send alerts if any
if alerts:
for alert in alerts:
industrial_command(
protocol='telegram',
command='send_message',
data=alert
)
4. Send Commands to Actuator Nodes
You can also control relay nodes in the mesh. Suppose you have a relay node that listens for ESP-NOW commands to turn a pump on/off. The AI can instruct the gateway to send a command back over ESP-NOW.
The gateway sketch needs a function to send ESP-NOW data. Add this to the sketch:
// In gateway sketch – send command to a specific node
void sendCommand(uint8_t *targetMac, const char *cmd) {
esp_now_peer_info_t peerInfo;
memcpy(peerInfo.peer_addr, targetMac, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("Failed to add peer");
return;
}
esp_now_send(targetMac, (uint8_t *)cmd, strlen(cmd) + 1);
}
Then in the AI chat, you say:
"Send command 'PUMP_ON' to the relay node with MAC AA:BB:CC:DD:EE:FF."
The AI will call serial_write_and_read with a hex string like 50554d505f4f4e0a ("PUMP_ON\n"). The gateway’s loop() reads this from Serial, parses it, and calls sendCommand().
Real-World Scenario: Greenhouse Automation
A practical use case: a 500 m² greenhouse with 20 ESP32 nodes. Each node has:
- DHT22 (temperature/humidity)
- Soil moisture sensor
- Relay for drip irrigation
- PIR motion sensor (for pest detection)
The nodes broadcast data every 30 seconds via ESP-NOW. The gateway collects everything and sends it to ASI Biont. The AI agent:
- Monitors soil moisture – if below 30%, triggers irrigation relay.
- Tracks temperature trends – if temperature rises faster than 2°C per hour, opens ventilation relay.
- Detects motion patterns – if motion is detected at night, sends a Telegram alert (possible animal intrusion).
- Logs everything to a CSV file stored in the ASI Biont sandbox for later analysis.
All of this is configured through chat. No dashboard, no YAML files. The AI writes the Python logic and executes it in the sandbox. The bridge handles the hardware layer.
Why This Matters: AI as the Integration Glue
Traditional IoT platforms require you to write custom firmware, set up MQTT brokers, and configure rules engines. With ASI Biont, you just describe what you want. The AI agent:
- Generates the bridge configuration (baud rate, port).
- Writes the parsing logic for any sensor protocol (even custom formats).
- Creates conditional automation rules on the fly.
- Connects to external services (Telegram, email, databases) without extra code.
Because the AI uses the execute_python sandbox with libraries like pyserial, paho-mqtt, requests, and pandas, it can handle any data format — CSV, JSON, XML, or raw binary. And if your device speaks Modbus, BACnet, or OPC UA, the AI can use those protocols too (as listed in the introduction).
Conclusion
ESP-NOW is a fantastic protocol for low-latency, dense sensor networks — but it needs a brain. By connecting an ESP32 gateway to ASI Biont via a COM port and the Hardware Bridge, you get a central AI that can parse data, make decisions, and send commands back into the mesh. The result: a fully autonomous IoT system with sub-3ms latency, no router dependency, and zero manual coding.
Try it yourself. Go to asibiont.com, create an API key, download the bridge, and plug in your ESP32. Then tell the AI: "I have an ESP-NOW gateway on COM3 at 115200 baud. Read temperature and humidity, and alert me if it gets too hot." The AI will do the rest.
References:
- Espressif ESP-NOW User Guide, 2023. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html
- ASI Biont Hardware Bridge Documentation (in-app help).
- IEEE 802.11-2020 Standard for Information Technology.
Comments