Why Connect Ethernet Modules to an AI Agent?
Ethernet modules like the W5500 (SPI-based, 10/100 Mbps) and ENC28J60 (also SPI, 10 Mbps) are the backbone of wired IoT connectivity for microcontrollers (Arduino, ESP32, STM32). They offer a stable, low-latency alternative to Wi-Fi, ideal for smart home hubs, industrial sensors, or security systems where reliability matters. By integrating these modules with the ASI Biont AI agent, you can automate data collection, control actuators, and trigger alerts—all without cloud dependencies or manual coding. The AI handles the integration logic, letting you focus on the use case.
How ASI Biont Connects to Ethernet Modules
ASI Biont supports multiple connection methods, but for Ethernet modules on microcontrollers, the most practical approach is MQTT (via paho-mqtt) or Modbus/TCP (via pymodbus). Here’s why:
- MQTT is lightweight and works well with ESP32/Arduino boards running a simple MQTT client. The AI subscribes to topics where the board publishes sensor data (e.g., temperature) and publishes commands to control relays or LEDs.
- Modbus/TCP is ideal for industrial controllers or PLCs that speak Modbus. The AI reads registers or coils directly over TCP/IP.
Both methods require the microcontroller to have a working TCP/IP stack (W5500 or ENC28J60 with appropriate library). The AI never talks to the Ethernet module directly—it communicates over the network via the chosen protocol.
Real-World Use Case: ESP32 + W5500 + DHT22 + ASI Biont
Problem: A user wants to monitor temperature and humidity in a server room using a wired ESP32 with a DHT22 sensor, and receive Telegram alerts when the temperature exceeds 30°C. No Wi-Fi available—only Ethernet.
Solution:
1. Hardware setup:
- ESP32 board with W5500 Ethernet module (SPI: CS=5, MOSI=23, MISO=19, SCK=18).
- DHT22 sensor connected to GPIO4.
- Power via USB or 5V adapter.
2. Microcontroller code (Arduino IDE):
- Use Ethernet2 library for W5500 (or UIPEthernet for ENC28J60).
- Use DHT library for sensor reading.
- Use PubSubClient for MQTT. Publish to topic sensor/temperature every 10 seconds.
3. ASI Biont integration:
- User tells the AI: “Connect to MQTT broker at 192.168.1.100:1883, subscribe to sensor/temperature, and send a Telegram message if value > 30. Also, publish relay/control with payload ON when temperature > 30.”
- AI writes a Python script using paho-mqtt that runs in the sandbox (execute_python). It subscribes to the topic, parses the JSON payload, and publishes to Telegram via requests (Telegram Bot API).
Code example (AI-generated):
import paho.mqtt.client as mqtt
import requests
import json
TELEGRAM_TOKEN = "your_bot_token"
CHAT_ID = "your_chat_id"
def on_message(client, userdata, msg):
payload = json.loads(msg.payload.decode())
temp = payload.get("temperature")
if temp > 30:
# Send Telegram alert
requests.post(f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage",
json={"chat_id": CHAT_ID, "text": f"Alert! Temperature {temp}°C"})
# Turn on relay
client.publish("relay/control", "ON")
client = mqtt.Client()
client.on_message = on_message
client.connect("192.168.1.100", 1883, 60)
client.subscribe("sensor/temperature")
client.loop_forever()
Results: The AI runs this script in the cloud (sandbox timeout: 30 seconds per execution). For persistent monitoring, use the industrial_command tool with MQTT protocol—AI can schedule periodic checks. The user gets Telegram alerts and can manually toggle the relay via chat commands.
Alternative: Hardware Bridge for Serial-to-Ethernet
If your Ethernet module is connected via a USB-to-serial adapter (e.g., W5500 as a shield on Arduino Uno), use the Hardware Bridge method:
- Run bridge.py on your PC (download from ASI Biont dashboard).
- Connect to COM3 at 115200 baud.
- AI sends commands via industrial_command(protocol='serial', command='serial_write_and_read', data='48454c500a') to query the device. The bridge writes to COM port and reads response.
- The microcontroller firmware must respond to simple text commands (e.g., TEMP? returns 25.4).
This is slower but works for legacy setups.
Why This Matters: No Coding Required
With ASI Biont, you don’t write the integration code manually. You just describe your setup: “I have an ESP32 with W5500, DHT22, MQTT broker at 192.168.1.100, topic sensor/temp. Send alerts to Telegram.” The AI generates the Python script and runs it. If you need to change the threshold or add a new sensor, just chat with the AI. It’s that simple.
Pitfalls to Avoid
- Wi-Fi vs Ethernet: Ensure your board firmware uses the correct library (Ethernet2 for W5500, UIPEthernet for ENC28J60). Mixing them causes crashes.
- MQTT QoS: Use QoS 0 for sensors (fire-and-forget), QoS 1 for commands. QoS 2 is overkill for most home setups.
- Firewall: The MQTT broker must be reachable from the ASI Biont server (e.g., port 1883 open). For cloud-based brokers like HiveMQ, no issue.
- Sandbox limits: The execute_python environment has a 30-second timeout. For long-running tasks, use industrial_command with MQTT subscription (which persists).
Conclusion
Integrating Ethernet modules (W5500, ENC28J60) with ASI Biont unlocks reliable, wired IoT automation for smart homes and industrial projects. Whether you use MQTT, Modbus/TCP, or Hardware Bridge, the AI handles the heavy lifting—you just describe the task. Try it today: asibiont.com.
Comments