From HC-05 to AI: How to Control BLE Devices with ASI Biont (Real Code + Telegram Alerts)

You’ve got an HC-05 or HM-10 Bluetooth module lying around, and you’re thinking: “Can I connect this to an AI agent and make it do something smart?”

Short answer: Yes, and it’s surprisingly easy.

In this guide, I’ll show you exactly how to integrate BLE/Bluetooth serial modules (HC-05, HM-10) with the ASI Biont AI agent. We’ll cover:
- Which connection method works best (Hardware Bridge + COM port)
- A real use case: ESP32 + DHT22 → ASI Biont → Telegram alerts
- Step-by-step code examples in Python and MicroPython
- Why you don’t need to write the integration yourself — ASI Biont does it for you

Let’s dive in.


1. What Are HC-05 / HM-10 and Why Connect Them to an AI Agent?

HC-05 and HM-10 are Bluetooth serial modules that let microcontrollers (Arduino, ESP32, STM32) communicate wirelessly with a PC, phone, or another MCU. They use the UART protocol (TX/RX pins) and appear as a virtual COM port on your computer after pairing.

Feature HC-05 HM-10
Bluetooth version 2.0 (Classic) 4.0 (BLE)
Role Master/Slave BLE Peripheral/Central
Data rate Up to 2 Mbps Up to 1 Mbps
Range ~10 m ~50 m (open field)
Power consumption ~50 mA ~10 mA (low energy)

Why connect to an AI agent?
- Remote monitoring: Read sensor data (temperature, humidity, distance) from anywhere via Telegram.
- Automation: Turn relays on/off based on AI‑generated rules (e.g., “if temp > 30°C, turn on fan”).
- No coding: You describe the task in chat, and the AI writes the bridge code in seconds.


2. Which Connection Method Does ASI Biont Use?

ASI Biont connects to Bluetooth modules via Hardware Bridge — a small Python script (bridge.py) that runs on your local PC. The bridge opens a COM port (e.g., COM3) and communicates with ASI Biont’s cloud server using HTTP long polling. The AI agent sends commands through the industrial_command tool, which routes them to your bridge, and the bridge reads/writes to the serial port.

Why not MQTT or SSH?
- BLE modules don’t have Wi‑Fi or Ethernet — they only speak serial.
- Hardware Bridge is the only way to reach a local COM port from the cloud AI.

Comparison with other methods:

Method When to use
Hardware Bridge (COM) HC‑05/HM‑10, Arduino, USB‑serial sensors
MQTT ESP32 with Wi‑Fi, smart home devices
SSH Raspberry Pi, Linux servers
Modbus/TCP Industrial PLCs

3. Real Use Case: ESP32 + DHT22 + HC-05 → ASI Biont → Telegram Alerts

Let’s build a system that:
- ESP32 reads temperature and humidity from a DHT22 sensor.
- ESP32 sends the data over Bluetooth (HC‑05) to a PC.
- The PC bridge forwards the data to ASI Biont.
- The AI agent analyzes the data and sends a Telegram alert if temperature exceeds 30°C.

3.1 Hardware Setup

  1. Connect DHT22 to ESP32:
  2. DHT22 VCC → ESP32 3.3V
  3. DHT22 GND → ESP32 GND
  4. DHT22 DATA → ESP32 GPIO4
  5. Connect HC‑05 to ESP32:
  6. HC‑05 TX → ESP32 RX (GPIO16)
  7. HC‑05 RX → ESP32 TX (GPIO17)
  8. HC‑05 VCC → ESP32 5V (or 3.3V – check module specs)
  9. HC‑05 GND → ESP32 GND

3.2 MicroPython Code for ESP32

import machine
import dht
import utime
from machine import UART

sensor = dht.DHT22(machine.Pin(4))
# HC‑05 connected to UART2 (TX=GPIO17, RX=GPIO16)
bt = UART(2, baudrate=9600)

while True:
    try:
        sensor.measure()
        temp = sensor.temperature()
        hum = sensor.humidity()
        # Format: TEMP:25.5,HUM:60.2
        msg = f"TEMP:{temp:.1f},HUM:{hum:.1f}\n"
        bt.write(msg)
        utime.sleep(5)
    except Exception as e:
        print("Sensor error:", e)

3.3 PC Side: Hardware Bridge

Download bridge.py from the ASI Biont docs. Run it with:

python bridge.py --token=YOUR_AUTH_TOKEN --ports=COM3 --default-baud=9600

The bridge will connect to ASI Biont and start polling for commands.

3.4 AI Integration (Chat with ASI Biont)

You tell the AI:

“Connect to COM3 at 9600 baud. Read incoming data in format TEMP:xx,HUM:yy. If temperature > 30°C, send a Telegram alert to my chat ID 123456789. Log all readings to a CSV file.”

ASI Biont generates and runs this Python code inside its sandbox (using industrial_command with protocol='serial://'):

# AI-generated script (runs in ASI Biont sandbox)
import json
import csv
from datetime import datetime

# ... (bridge communication via industrial_command)
# The AI uses the command tool to send/receive serial data
# Example: industrial_command(protocol='serial://', command='read', parameters={'port': 'COM3', 'baud': 9600})
# Then it parses the returned string and checks conditions.

Result:
- Every 5 seconds, the AI receives temperature and humidity.
- If temp > 30°C, it calls the Telegram API and sends: “🔥 Temperature exceeded 30°C! Current: 31.2°C”.
- All data is saved to a CSV file on the bridge PC.


4. How to Connect (Step-by-Step for Any BLE Device)

  1. Pair your HC‑05/HM‑10 with your PC (default PIN: 1234 or 0000).
  2. Windows: Bluetooth settings → Add device → COM port appears (e.g., COM5).
  3. Linux: sudo rfcomm bind /dev/rfcomm0 XX:XX:XX:XX:XX:XX 1.
  4. Note the COM port name and baud rate (usually 9600 or 115200).
  5. Start the Hardware Bridge on your PC:
    bash python bridge.py --token=MY_TOKEN --ports=COM5 --default-baud=9600
  6. In ASI Biont chat, describe your device:

    “I have a Bluetooth module on COM5, 9600 baud. I want to read data from it and control a relay. Send me a notification if I receive the word ‘ALERT’.”

  7. The AI writes and runs the integration code instantly.

No dashboard. No “Add device” button. Just a conversation.


5. Why This Approach Wins Over Traditional Coding

  • Speed: Integration takes 10 seconds of typing, not hours of debugging.
  • Flexibility: Change the logic on the fly (“Now also log to Google Sheets”).
  • No vendor lock‑in: ASI Biont connects to any device via execute_python — you’re not limited to a predefined list.
  • Real‑time alerts: Telegram, email, Slack — whatever you want.

Pitfalls to avoid:
- Don’t use an infinite loop in execute_python (30‑second timeout). Instead, let the bridge poll data and send it to the AI.
- Make sure the baud rate matches between the module and the bridge.
- On Windows, some HC‑05 clones show as “Standard Serial over Bluetooth link” — that’s fine, use that COM port.


6. Advanced Scenario: BLE Sensor Network

You can scale this to multiple BLE modules. Example: three HM‑10 modules each with a soil moisture sensor in a greenhouse. The bridge polls all three COM ports (COM3, COM4, COM5). ASI Biont aggregates data, detects dry soil, and triggers a relay to open a water valve.

The AI code would use a loop over ports and publish to MQTT for visualization:

# Example snippet (AI-generated, runs in sandbox)
import paho.mqtt.client as mqtt
# ... read from each port via industrial_command, then publish
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("greenhouse/moisture/1", "25%")

7. Conclusion: Stop Writing BLE Boilerplate — Let AI Do It

Bluetooth modules like HC‑05 and HM‑10 are perfect for short‑range, low‑power IoT projects. But manually writing serial parsers, error handling, and notification logic is tedious. With ASI Biont, you describe what you want, and the AI generates the entire integration — from reading the COM port to sending Telegram alerts.

Try it yourself:
- Grab an HC‑05, an Arduino, and a sensor.
- Go to asibiont.com.
- Tell the AI: “Connect to my Bluetooth module on COM3 and notify me when the button is pressed.”
- See the magic happen in real time.

Your next smart project is one chat message away.

← All posts

Comments