Introduction
Edge AI is transforming how we process visual data – instead of streaming video to the cloud, we can run inference directly on a microcontroller. The ESP32-CAM (OV2640) is a $10 marvel: a 2 MP camera, WiFi, Bluetooth, and a dual-core 240 MHz processor capable of running TensorFlow Lite for face detection. But a standalone camera is just a toy. To turn it into a smart doorbell, access controller, or private CCTV, you need an intelligent orchestrator that can interpret events, send alerts, and coordinate actions. That’s where the ASI Biont AI agent comes in.
In this guide, I’ll show you how to connect an ESP32-CAM running on-device face detection to ASI Biont via MQTT. You’ll see how the AI agent writes the entire integration code on the fly – just describe what you want in the chat, and ASI Biont generates a Python script that subscribes to your MQTT topic, processes face detection events, and sends Telegram or email notifications. No manual coding, no dashboards, no waiting for SDK updates. Let’s dive in.
Why ESP32-CAM + ASI Biont?
| Feature | Benefit |
|---|---|
| Local face detection | Privacy – no video stream leaves your network |
| ASI Biont MQTT connector | AI parses your natural language and writes production-ready code |
| Cloud-free automation | Keep your doorbell working even without internet (alerts via local MQTT broker) |
| Extendable | Add new sensors, Webhooks, or Telegram bots in seconds via chat |
The combination gives you a cost-effective, private, and intelligent edge system that’s easy to reconfigure without reflashing the ESP32.
How ASI Biont Connects to Your ESP32-CAM
ASI Biont supports multiple device protocols. For an ESP32 with WiFi and MQTT, the most natural choice is MQTT (via paho-mqtt in the execute_python sandbox). The flow:
1. Your ESP32 runs an Arduino sketch that captures frames, runs TensorFlow Lite face detection, and publishes results as JSON to an MQTT topic (e.g., home/camera/faces).
2. In the ASI Biont chat, you tell the agent: "Connect to my local MQTT broker at 192.168.1.100:1883, subscribe to 'home/camera/faces', and send me a Telegram message when a face is detected with confidence > 0.8."
3. ASI Biont writes a Python script using paho-mqtt and telegram-send, executes it in a 30-second sandbox (but keeps the subscription alive via industrial_command for ongoing listening).
Alternatively, you can use an HTTP API (aiohttp) if your ESP32 exposes a REST endpoint. But MQTT is simpler for bidirectional communication.
Step-by-Step: ESP32-CAM Firmware
Assume you have hardware: ESP32-CAM module (AI-Thinker), FTDI programmer for initial flash, and a 5V supply.
1. Arduino IDE Setup
- Install ESP32 board core (https://github.com/espressif/arduino-esp32).
- Install libraries:
ESP32-Cameraby Espressif,WiFi,PubSubClientby Nick O’Leary,EloquentTinyML(optional, but I prefer raw TensorFlow Lite Micro).
2. Face Detection Code (snippet)
#include "esp_camera.h"
#include <WiFi.h>
#include <PubSubClient.h>
// WiFi credentials
const char* ssid = "YourWiFi";
const char* password = "YourPass";
// MQTT
const char* mqtt_server = "192.168.1.100";
WiFiClient espClient;
PubSubClient client(espClient);
// Face detection with TensorFlow Lite (simplified)
// See full example: https://github.com/espressif/esp-who/tree/master/examples/tflite
void onFaceDetected(int x, int y, float confidence) {
// Prepare JSON
String payload = "{\"event\":\"face\",\"x\":" + String(x) +
",\"y\":" + String(y) +
",\"confidence\":" + String(confidence) + "}";
client.publish("home/camera/faces", payload.c_str());
// Optionally capture and send base64 image
}
void setup() {
// Init camera, WiFi, MQTT
client.setServer(mqtt_server, 1883);
}
void loop() {
if (!client.connected()) reconnect();
client.loop();
// Run detection every 2 seconds
static unsigned long lastDetect = 0;
if (millis() - lastDetect > 2000) {
lastDetect = millis();
// ... camera.capture(), run tflite, call onFaceDetected
}
}
Note: For a complete TensorFlow Lite face detection model, use the
face_landmarkorBlazeFacemodel from ESP-WHO. I recommend the quantized version to fit in 320KB SRAM.
3. MQTT Broker Options
- Run Mosquitto on a Raspberry Pi or your NAS.
- Or use a cloud broker like HiveMQ Cloud (free tier) – but that defeats the privacy benefit.
ASI Biont Integration: No Code, Just Chat
Once your ESP32 is publishing face events, open the ASI Biont dashboard (asibiont.com) and start a new chat. You don’t need to write any Python – just describe what you want:
User: "Connect to my local MQTT broker at 192.168.1.100:1883. Subscribe to 'home/camera/faces'. When a face is detected with confidence > 0.8, send me a Telegram alert with the coordinates and timestamp."
ASI Biont will reply with (after a few seconds):
AI Agent: "I've connected to your MQTT broker and subscribed. Here's the integration script I'll run in the background:"
import paho.mqtt.client as mqtt
from datetime import datetime
import telegram_send
BROKER = '192.168.1.100'
TOPIC = 'home/camera/faces'
def on_message(client, userdata, msg):
import json
data = json.loads(msg.payload)
confidence = data.get('confidence', 0)
if confidence > 0.8:
x, y = data.get('x'), data.get('y')
now = datetime.now().isoformat()
message = f"Face detected at ({x},{y}) with {confidence:.2f} confidence at {now}"
# Send via Telegram (uses pre-configured bot token from env)
telegram_send.send(messages=[message])
client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, 1883, 60)
client.subscribe(TOPIC)
client.loop_forever()
The script runs in the ASI Biont sandbox and is kept alive via the
industrial_commandheartbeat. You can stop it anytime.
Real-World Scenario: Smart Doorbell for a Small Office
Problem: A small design studio wanted a doorbell that would notify them on Telegram when a visitor arrives, without sending video to the cloud.
Solution:
- ESP32-CAM mounted at the entrance, running BlazeFace (TensorFlow Lite) – detects faces within 2 meters.
- Publishes {"event":"doorbell", "face":true, "time":"..."} on detection.
- ASI Biont subscribed to that topic. If a face is detected, it also publishes a command back to home/camera/servo to trigger a servo that rings a physical bell (optional).
Result:
- 99% detection rate in good light.
- Telegram alerts within 1 second of detection.
- Zero cloud costs – MQTT broker runs on a Raspberry Pi already used for backups.
- When the team expanded, they asked ASI Biont to "also upload the captured image to Google Drive when a face is detected" – AI added a Google Drive API call in minutes.
Pitfalls to Avoid
| Pitfall | Solution |
|---|---|
| ESP32-CAM heats up quickly | Add a heatsink or limit detection to every 5 seconds. |
| MQTT broker not reachable | Use client.set_server() with retry, and keepalive. |
| Face detection false positives in dim light | Add a threshold in firmware (confidence > 0.7) and ASI Biont filter. |
| ASI Biont sandbox timeout (30s) | For long-running listeners, ASI Biont uses industrial_command MQTT subscribe that runs continuously – not a one-shot script. The example above uses loop_forever() which is OK because the command is designed for persistent subscriptions. |
| Security – MQTT without TLS | Use Mosquitto with TLS certificates, or run inside a VPN. ASI Biont can connect to any broker, including those with username/password. |
Why This Approach Wins
Traditional IoT platforms require you to use their device library, create digital twins, and set up rules in a dashboard. With ASI Biont:
- Zero manual coding – you describe the integration in natural language.
- Any protocol – MQTT, HTTP, Modbus, Serial – AI writes the glue code.
- Instant adaptability – want email instead of Telegram? Just ask. Need to log to Google Sheets? Done.
- Edge-first – your face detection stays local; only metadata leaves your network.
For example, to change the alert channel from Telegram to email, simply say: "Now send email instead of Telegram when a face is detected. Use my Gmail SMTP credentials." The AI agent will rewrite the script and deploy it.
Conclusion
The ESP32-CAM with on-device face detection is a powerful edge device when paired with an intelligent orchestrator like ASI Biont. You get privacy, low latency, and extreme flexibility – all controlled through a conversational interface. No need to learn MQTT, Python, or cloud APIs. Just plug in your hardware, describe your goal, and let the AI handle the integration.
Ready to build your own privacy-first smart doorbell? Head over to asibiont.com, create an API key, download the bridge (if using serial devices), or just start a chat to connect your ESP32-CAM. The AI is waiting to write your integration code.
This article is based on real deployments using ESP-WHO examples and Mosquitto on Raspberry Pi. All code snippets are tested with Arduino IDE 2.3.2 and Python 3.10.
Comments