Connect BLE Modules (HM-10, HC-05) to an AI Agent: A Step-by-Step Guide with ASI Biont

Why Integrate BLE Modules with an AI Agent?

Bluetooth Low Energy (BLE) modules like the HM-10 and HC-05 are ubiquitous in IoT projects — they let microcontrollers (Arduino, ESP32) talk wirelessly to phones, sensors, and actuators. But managing data from multiple BLE nodes, triggering actions based on sensor thresholds, or logging readings to a cloud service usually requires custom middleware and manual scripting. That’s where an AI agent like ASI Biont changes the game.

Instead of writing a separate server to parse serial data, forward commands, or set up a dashboard, you simply describe your setup in a chat. The AI selects the right connection method (Serial via Hardware Bridge, MQTT, or even HTTP if the BLE module is paired with an ESP32), writes the integration code, and runs it — all within seconds. This article shows you exactly how to do it, with real code and wiring examples.

Which Connection Method Works Best for BLE Modules?

BLE modules typically communicate over a serial UART interface using AT commands. To connect such a module to ASI Biont, you have two practical paths:

  1. Hardware Bridge (COM port): If your BLE module is directly attached to a PC via a USB-to-serial adapter (or to an Arduino that is connected via USB), run bridge.py on that PC. The bridge opens the COM port (e.g., COM3, /dev/ttyUSB0) at a given baud rate (usually 9600 or 115200) and establishes a WebSocket connection to ASI Biont’s cloud. You send commands via the industrial_command tool with serial_write_and_read(data="AT\r\n"), and the bridge writes to the serial port and returns the response.

  2. MQTT (if using ESP32 + BLE): If your BLE module is part of an ESP32 that also has Wi-Fi, you can forward BLE data over MQTT. The ESP32 reads sensor values from a BLE device (e.g., a temperature beacon) and publishes them to an MQTT broker. ASI Biont then subscribes to that topic using a Python script with paho-mqtt inside the execute_python sandbox.

For most simple HM-10/HC-05 setups (e.g., controlling an LED or reading a button), the Hardware Bridge method is the most straightforward.

Real-World Use Case: Controlling an LED via BLE and Telegram

Imagine you have an HM-10 module connected to an Arduino Uno. The Arduino listens for serial commands: LED_ON turns on an LED, LED_OFF turns it off. You want to control it from Telegram via an AI agent.

Step 1: Hardware Wiring

HM-10 Pin Arduino Pin
VCC 5V
GND GND
TX RX (pin 0)
RX TX (pin 1)

Also connect an LED (with a 220Ω resistor) to pin 13 and GND.

Step 2: Arduino Sketch

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  if (Serial.available()) {
    String cmd = Serial.readStringUntil('\n');
    cmd.trim();
    if (cmd == "LED_ON") {
      digitalWrite(13, HIGH);
      Serial.println("OK");
    } else if (cmd == "LED_OFF") {
      digitalWrite(13, LOW);
      Serial.println("OK");
    } else {
      Serial.println("UNKNOWN");
    }
  }
}

Step 3: Run bridge.py on Your PC

Download bridge.py from your ASI Biont dashboard (Devices → Create API Key → Download bridge). Install dependencies:

pip install pyserial requests websockets

Run it with your token and COM port:

python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud=9600

The bridge now connects to ASI Biont via WebSocket and listens for serial commands.

Step 4: Tell the AI Agent What to Do

In the ASI Biont chat, you write:

“Connect to the HM-10 on COM3 at 9600 baud. When I send the message ‘turn on’, write ‘LED_ON’ to the serial port. When I say ‘turn off’, write ‘LED_OFF’. Confirm the response.”

The AI agent uses the industrial_command tool like this (you don’t see this, it happens behind the scenes):

industrial_command(
  protocol="serial://",
  command="serial_write_and_read",
  data="LED_ON\n"
)

The bridge sends LED_ON\n to the Arduino, which replies OK. The AI reads that and responds in chat: “✅ LED turned on. Device replied: OK.”

Step 5: Automate with Telegram Bots

You can also connect your Telegram bot to ASI Biont. For example, set up a rule: “If the temperature sensor (connected via BLE to another ESP32) exceeds 30°C, send a Telegram alert and turn on a fan via the HM-10 relay.” The AI handles all the logic — no coding required.

Why This Approach Beats Traditional IoT Middleware

  • No manual integration code: You don’t write a Flask server or a Node-RED flow. The AI generates the glue code on the fly.
  • Flexible protocols: ASI Biont supports 14+ connection methods — Serial, MQTT, SSH, Modbus, OPC-UA, BACnet, etc. If your BLE module is part of a larger system, you can mix methods.
  • Real-time control via chat: Send a message in Telegram, Slack, or the web interface, and the AI executes the command instantly.
  • Self‑healing: If the bridge disconnects, the AI can detect it and ask you to restart, or you can set up auto‑reconnection in the bridge script.

Common Pitfalls and How to Avoid Them

  1. Baud rate mismatch: Ensure the Arduino sketch and the bridge config use the same baud rate. HM-10 defaults to 9600, but some clones use 115200. Verify with a serial monitor first.
  2. Newline characters: The serial_write_and_read command sends data as-is. If your sketch expects a newline, include \n in the data string. In hex, that’s 0A.
  3. Buffer overflows: If you send commands too fast, the Arduino’s 64‑byte serial buffer may overflow. Use a rate limiter in bridge.py (--rate=10 limits to 10 commands per second).
  4. Windows COM port issues: On Windows, pyserial may fail with overlapped I/O errors. The bridge automatically falls back to CancelIoEx + PurgeComm + synchronous WriteFile — this is handled for you.

Try It Yourself

You don’t need to wait for developers to add BLE support — ASI Biont connects to any device through execute_python. Just describe your hardware in the chat: “I have an HM-10 on /dev/ttyUSB0 at 9600 baud, please read the button state every 5 seconds and log it.” The AI writes the Python code using pyserial, runs it in the sandbox, and starts collecting data immediately.

No dashboards, no “add device” buttons — just conversation.

👉 Start integrating your BLE modules today at asibiont.com.


This guide references the official ASI Biont documentation for Hardware Bridge and industrial_command tool. For more details, see the in‑app help or the bridge.py source comments.

← All posts

Comments