Introduction: Why Connect LoRa/LoRaWAN Devices to an AI Agent?
LoRa (Long Range) and LoRaWAN (Long Range Wide Area Network) are wireless protocols designed for low-power, long-range IoT communication. They are used in smart agriculture (soil moisture sensors), asset tracking (GPS trackers), environmental monitoring (weather stations), and industrial telemetry (tank level sensors). These devices transmit small data packets over kilometers with battery life spanning years—ideal for remote, hard-to-reach locations.
However, extracting value from LoRa data often requires setting up a network server (like ChirpStack or The Things Network), writing custom Python scripts to parse uplinks, and building dashboards or alerting systems. This is time-consuming and requires coding expertise. ASI Biont, an AI agent that connects to any device via chat, eliminates this friction. You simply describe your LoRaWAN device and the data you want to process, and the AI writes the integration code on the fly—using MQTT (common for The Things Network) or a direct serial connection via a LoRa gateway’s COM port.
In this article, we’ll explore how ASI Biont connects to LoRa/LoRaWAN devices, focusing on a real-world use case: a remote temperature and humidity sensor sending data via a LoRaWAN gateway. We’ll cover the connection method (MQTT and COM port via Hardware Bridge), a step-by-step setup, and the benefits of AI-driven automation.
How ASI Biont Connects to LoRa/LoRaWAN Devices
ASI Biont supports two primary pathways for LoRaWAN integration:
-
MQTT (via execute_python): Most LoRaWAN network servers (The Things Network, ChirpStack, Helium) expose MQTT topics for uplink and downlink. ASI Biont’s sandbox (execute_python) uses the
paho-mqttlibrary to subscribe to these topics, parse JSON payloads (often base64-encoded), and trigger actions (alerts, logging, control). -
COM port via Hardware Bridge (bridge.py): If you have a LoRa gateway with a serial interface (e.g., a Dragino LG01 or a RAK7249 with RS-232), you can connect it to a PC running bridge.py. The AI sends commands via WebSocket to bridge.py, which reads/writes to the COM port. This is useful for direct AT command control of LoRa modules (e.g., HopeRF RFM95) or parsing raw serial data from a gateway.
For this case study, we’ll use the MQTT pathway because it’s the standard for cloud-connected LoRaWAN deployments. The AI will subscribe to The Things Network (TTN) MQTT broker, decode sensor data from a Dragino LHT65 (temperature/humitude sensor), and send Telegram alerts when thresholds are exceeded.
Real-World Use Case: Remote Temperature Monitoring with Alerting
Problem: A warehouse in a remote area uses a Dragino LHT65 LoRaWAN sensor to monitor temperature and humidity. Data is sent every 10 minutes to TTN. The warehouse manager needs instant alerts (via Telegram) when temperature exceeds 30°C, and a daily summary report—without writing any code or managing infrastructure.
Solution with ASI Biont: The user describes the task in the chat: “Subscribe to TTN MQTT topic for my LHT65 sensor, decode the payload, log temperature to Google Sheets, and send a Telegram alert if temp > 30°C.” The AI generates a Python script using paho-mqtt, requests, and json, then runs it in the sandbox. Here’s the actual code the AI would produce:
import paho.mqtt.client as mqtt
import json
import base64
import requests
from datetime import datetime
# Configuration (provided by user in chat)
TTN_APP_ID = "my-warehouse-app"
TTN_ACCESS_KEY = "ttn-account-v2.XXXXXXXX"
TELEGRAM_BOT_TOKEN = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
TELEGRAM_CHAT_ID = "-1001234567890"
# Decode LHT65 payload (Cayenne LPP format)
def decode_lht65(payload_hex):
bytes_data = bytes.fromhex(payload_hex)
if len(bytes_data) < 4:
return None
# Channel 1: temperature (2 bytes, big-endian, 0.01°C resolution)
temp_raw = int.from_bytes(bytes_data[1:3], 'big', signed=True)
temperature = temp_raw * 0.01
# Channel 2: humidity (1 byte, 0.5% resolution)
humidity = bytes_data[3] * 0.5
return {"temperature": round(temperature, 2), "humidity": round(humidity, 1)}
# MQTT callback
def on_message(client, userdata, msg):
topic = msg.topic
if "uplink" not in topic:
return
try:
payload = json.loads(msg.payload)
# TTN v3: payload_raw is base64
raw_hex = base64.b64decode(payload["uplink_message"]["frm_payload"]).hex()
data = decode_lht65(raw_hex)
if not data:
return
temp = data["temperature"]
hum = data["humidity"]
timestamp = datetime.utcnow().isoformat()
print(f"{timestamp} - Temp: {temp}°C, Hum: {hum}%")
# Alert if temperature > 30°C
if temp > 30.0:
message = f"⚠️ ALERT: Temperature {temp}°C exceeded threshold!"
requests.post(f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage",
json={"chat_id": TELEGRAM_CHAT_ID, "text": message})
print("Telegram alert sent.")
except Exception as e:
print(f"Error processing message: {e}")
# Connect to TTN MQTT
client = mqtt.Client()
client.username_pw_set(TTN_APP_ID, TTN_ACCESS_KEY)
client.on_message = on_message
client.connect("eu1.cloud.thethings.network", 1883, 60)
client.subscribe(f"v3/{TTN_APP_ID}@ttn/devices/+/up")
print("Listening for LoRaWAN uplinks...")
client.loop_forever()
How the user interacts: The user simply pastes their TTN App ID and Access Key in the chat, describes the sensor type (LHT65), and asks for alerts. The AI generates the script, runs it in the sandbox (with a 30-second loop timeout, but the script continues via industrial_command MQTT subscription method for persistence), and the integration is live within seconds.
Results:
- Temperature readings are decoded in real time.
- Alerts are sent to Telegram within 1 second of receiving the uplink.
- No server setup, no MQTT client configuration—just a conversation.
Step-by-Step: Connecting a LoRaWAN Device via COM Port (Alternative Method)
If you prefer a direct serial connection (e.g., using a LoRa module like an Ebyte E32 with UART), the Hardware Bridge method is ideal. Here’s how it works:
- User runs bridge.py on their PC with the COM port parameters:
python bridge.py --token=YOUR_API_KEY --ports=COM5 --baud 9600. - In the ASI Biont chat, the user says: “Connect to COM5 at 9600 baud, send AT command to my LoRa module to read RSSI, and return the value.”
- AI sends
industrial_command(protocol='serial', command='serial_write_and_read', data='41540d0a')(hex for “AT\r\n”). - Bridge.py writes “AT\r\n” to COM5, reads the response (e.g., “OK”), and sends it back to the AI.
- The AI interprets the response and continues the conversation.
This method is perfect for prototyping with raw LoRa modules or debugging gateway serial output.
Why ASI Biont + LoRaWAN Is a Game Changer
- Zero Coding: You don’t need to learn MQTT, payload decoders, or serial programming. The AI handles it all based on natural language descriptions.
- Universal Connectivity: ASI Biont supports any device through execute_python—it writes Python code with
paho-mqtt,pyserial,paramiko,aiohttp, oropcua-asyncioas needed. No waiting for platform updates. - Immediate Automation: From data collection to alerting to cloud logging (Google Sheets, databases), everything happens in one chat session.
- Real Monitoring: For persistent MQTT subscriptions, the AI uses the industrial_command tool with a dedicated MQTT listener, ensuring 24/7 operation without manual scripts.
Conclusion
LoRaWAN devices are powerful for remote IoT, but their integration has traditionally been a barrier for non-developers. ASI Biont removes that barrier entirely. Whether you use MQTT via The Things Network or a direct serial connection to a gateway, the AI agent writes and runs the integration code in seconds. You just describe what you need in plain English.
Try it yourself: go to asibiont.com, create an API key, download bridge.py, and tell the AI to connect your LoRa sensor. No coding, no waiting—just results.
Comments