The Problem: Manual Logs and Insecure Access
In many small labs, co-working spaces, or server rooms, access control still relies on physical keys or shared PIN codes. Neither provides audit trails: you never know who entered, at what time, or whether the door was left open. RFID-based systems solve this, but traditional setups require writing firmware (Arduino sketches), configuring databases, and building dashboards. That’s where ASI Biont’s AI agent changes the game.
The Solution: RC522 + ESP32 + ASI Biont
Instead of spending days coding a full access system, you connect a $3 RC522 RFID module to an ESP32, and let ASI Biont’s AI handle the logic. The AI agent uses MQTT (via paho-mqtt running inside execute_python) to communicate with the ESP32, which publishes card UIDs and subscribes to commands (e.g., open relay, log entry).
Why MQTT?
| Method | Best for | Downside |
|---|---|---|
| COM port (Hardware Bridge) | Local PC directly connected to ESP32 | Requires bridge.py running on your computer |
| SSH | Raspberry Pi with RC522 | Needs full Linux setup |
| MQTT (this article) | ESP32 over Wi‑Fi | Requires a broker (Mosquitto) – but the AI can even set one up |
MQTT is ideal when the ESP32 is deployed in a remote location (e.g., on a door) and communicates wirelessly.
How the Integration Works
- Hardware: Wire the RC522 to ESP32 using SPI (SDA→GPIO5, SCK→GPIO18, MOSI→GPIO23, MISO→GPIO19, RST→GPIO4). Power from 3.3V and GND.
- ESP32 firmware: Upload a simple MicroPython script that connects to Wi‑Fi, reads UID from RC522, and publishes it as an MQTT message every time a card is tapped.
- ASI Biont AI: The user tells the AI: “Connect to MQTT broker at 192.168.1.100:1883, subscribe to topic 'rfid/uid'. When a known UID arrives, log the event and publish 'relay/open' to open the door.”
- AI generates and runs the Python script inside
execute_python– no manual coding needed.
Code Example: ESP32 Publisher (MicroPython)
import network
import time
from machine import Pin, SPI
from mfrc522 import MFRC522
from umqtt.simple import MQTTClient
# Wi‑Fi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('SSID', 'PASSWORD')
while not wlan.isconnected():
time.sleep(0.5)
# RFID reader
sck = Pin(18, Pin.OUT)
mosi = Pin(23, Pin.OUT)
miso = Pin(19, Pin.IN)
sda = Pin(5, Pin.OUT)
rst = Pin(4, Pin.OUT)
rc522 = MFRC522(sck, mosi, miso, sda, rst)
# MQTT
client = MQTTClient('esp32', '192.168.1.100')
client.connect()
while True:
uid = rc522.read_id()
if uid:
client.publish(b'rfid/uid', str(uid))
time.sleep(2)
time.sleep(0.2)
AI‑Generated Python Script for ASI Biont
The user simply describes the logic. The AI writes and runs this script inside execute_python (sandbox, 30‑second timeout – but loops are fine if the AI uses async or simple polling):
import paho.mqtt.client as mqtt
import json
ALLOWED_UIDS = {"1234567890": "Alice", "0987654321": "Bob"}
def on_message(client, userdata, msg):
uid = msg.payload.decode()
if uid in ALLOWED_UIDS:
user = ALLOWED_UIDS[uid]
print(f"Authorized: {user}")
# Publish command to open relay
client.publish("relay/open", "1")
# Log to file (sandbox allows file writes)
with open("access_log.csv", "a") as f:
f.write(f"{user},{uid}\n")
else:
print(f"Unknown UID: {uid}")
client = mqtt.Client()
client.connect("192.168.1.100", 1883, 60)
client.subscribe("rfid/uid")
client.on_message = on_message
client.loop_start()
# Keep running for 25 seconds (sandbox limit)
import time
time.sleep(25)
Note: The sandbox enforces a 30‑second timeout. For production, you would run a persistent script on your own server – but for prototyping and testing, this is more than enough.
Real‑World Scenario: Co‑Working Space Door
A small co‑working space with 20 members used a shared PIN pad. Members shared codes, and the owner had no way to see who came in after hours. After integrating RC522 with ASI Biont:
- Owner sends a chat message: “Add card UID 1234567890 for Alice, valid from 9 to 18”
- AI updates the access list and even adds time‑based rules.
- Each tap is logged with timestamp and member name.
- Alerts are sent via Telegram if an unknown card is used after midnight.
The whole integration took 7 minutes – from wiring to first authorized beep.
Why This Matters
You don’t need to be an embedded developer or write a single line of MQTT code. The ASI Biont AI agent reads the user’s plain‑language description, selects the right protocol (MQTT, Modbus, SSH, COM port), generates the Python script, and runs it. If you need a different protocol tomorrow – just ask.
“Connect the same RC522 via COM port on my laptop” – the AI switches to Hardware Bridge.
Conclusion
RFID access control is a classic “small problem, big overhead” task. With ASI Biont, you eliminate the overhead. The RC522 + ESP32 combo costs under $10, and the AI agent handles everything else: connection, logic, logging, and alerts.
Try it yourself – describe your RFID setup to the AI on asibiont.com and see the code appear in seconds.
Comments