Introduction
LoRa (Long Range) and LoRaWAN (the network protocol on top of LoRa) have become the backbone of low-power IoT deployments — from soil moisture sensors in agriculture to temperature monitors in cold chains. The challenge? Extracting actionable intelligence from the raw data these devices send. This article is a practical guide to connecting a LoRaWAN-enabled sensor (e.g., Dragino LHT65 temperature/humidity node or a custom LoRa module) to the ASI Biont AI agent. Instead of writing integration code from scratch, you describe your hardware in plain English, and ASI Biont generates and executes the Python code on the spot.
Which Connection Method and Why
ASI Biont supports multiple industrial protocols, but LoRaWAN gateways typically expose data through a COM port (RS-232/RS-485) or via MQTT (when the gateway has built-in broker support). For this article, we focus on the COM port method because many popular LoRaWAN gateways (like the Dragino LG01 or Kerlink iBTS) provide a serial console that outputs received frames as JSON or binary packets. The connection chain is:
- LoRa sensor → (LoRa radio) → LoRaWAN gateway → (USB/serial) → user's PC → Hardware Bridge (bridge.py) → WebSocket → ASI Biont cloud.
The user runs bridge.py on their local machine (Windows/Linux/macOS), specifying the COM port and baud rate. The AI agent then uses the industrial_command tool with serial_write_and_read to send queries and read responses. No HTTP API, no dashboards — just a chat conversation.
Concrete Use Case: Dragino LHT65 Temperature/Humidity Sensor
Scenario: You have a Dragino LHT65 sensor deployed in a greenhouse. It sends temperature and humidity readings every 30 minutes via LoRaWAN to a Dragino LG01 gateway. The gateway is connected to your PC on COM5 at 115200 baud. You want ASI Biont to:
1. Read the latest sensor frame from the gateway's serial output.
2. Parse the JSON payload (containing temperature_C and humidity_RH).
3. Log the values to a CSV file.
4. Send a Telegram alert if temperature exceeds 35°C or humidity drops below 40%.
Step 1: Set up Hardware Bridge
Download bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge). Launch it with:
pip install pyserial requests websockets
python bridge.py --token=YOUR_API_TOKEN --ports=COM5 --baud=115200 --rate=10
The bridge connects to ASI Biont via WebSocket and opens COM5 at 115200 baud. The --rate=10 limits command execution to 10 per second.
Step 2: Describe the Task in Chat
In the ASI Biont chat, you write:
"Connect to COM5 at 115200 baud. Read the latest LoRaWAN payload from the Dragino LG01 gateway. The gateway outputs JSON frames like
{\"temperature_C\": 28.5, \"humidity_RH\": 62}. Log each reading to a CSV file and alert me via Telegram if temperature > 35°C or humidity < 40%."
Step 3: AI Generates and Executes the Code
ASI Biont uses the industrial_command tool to send a serial_write_and_read command to the bridge. It may also write a Python script (via execute_python) to handle parsing, logging, and alerts. Here is a simplified version of what the AI might produce:
import csv
import json
import os
from datetime import datetime
from paho.mqtt import publish # For Telegram alert via MQTT broker
# Simulating reading from bridge (actual call uses industrial_command)
# raw_data = serial_write_and_read(data="GET_LATEST_JSON\n")
raw_data = '{"temperature_C": 36.2, "humidity_RH": 38}' # example response
try:
payload = json.loads(raw_data)
temp = payload["temperature_C"]
hum = payload["humidity_RH"]
timestamp = datetime.now().isoformat()
# Log to CSV
file_exists = os.path.isfile("sensor_log.csv")
with open("sensor_log.csv", "a", newline="") as f:
writer = csv.writer(f)
if not file_exists:
writer.writerow(["timestamp", "temperature_C", "humidity_RH"])
writer.writerow([timestamp, temp, hum])
# Alert if out of range
if temp > 35 or hum < 40:
alert_msg = f"ALERT: Temp={temp}°C, Hum={hum}% (thresholds: >35°C or <40%)"
publish.single("telegram/alerts", alert_msg, hostname="mqtt.example.com")
print(alert_msg)
else:
print(f"OK: Temp={temp}°C, Hum={hum}%")
except Exception as e:
print(f"Parse error: {e}")
The script runs in the ASI Biont sandbox (30-second timeout). The MQTT publish step forwards the alert to a Telegram bot (configured via an MQTT-to-Telegram bridge).
Why This Approach Works
- Zero manual coding: You describe the hardware and the logic — ASI Biont writes and runs the code.
- Any LoRaWAN gateway: As long as it exposes a serial port or MQTT topic, the AI can connect via
bridge.pyorpaho-mqtt. - Real-time automation: Alerts, data logging, and even actuator commands (e.g., turning on a fan via a relay) can be triggered without human intervention.
- Extensible: The same pattern works for any COM-port device: GPS trackers (NMEA), industrial sensors (Modbus RTU), or Arduino-based controllers.
Alternative Connection: MQTT with LoRaWAN
If your LoRaWAN gateway (like The Things Network stack) publishes data to an MQTT broker, you can skip the serial bridge. In the chat, simply say:
"Connect to MQTT broker at broker.hivemq.com:1883, subscribe to topic 'lorawan/+/up', parse the JSON payload, and log temperature readings."
ASI Biont then uses paho-mqtt inside execute_python to subscribe and process messages:
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
print(f"Received: {msg.payload}")
# parse and log
client = mqtt.Client()
client.connect("broker.hivemq.com", 1883, 60)
client.subscribe("lorawan/+/up")
client.on_message = on_message
client.loop_start() # runs for 30 seconds
Conclusion
Integrating LoRaWAN sensors with an AI agent like ASI Biont transforms raw telemetry into intelligent action — without writing a single line of boilerplate code. Whether you use a COM-port bridge or MQTT, the process is the same: describe your hardware and logic in natural language, and the AI handles the integration. No waiting for SDK updates, no complex dashboards. Just talk to your data.
Ready to connect your LoRaWAN sensor to an AI brain? Go to asibiont.com, download the bridge, and start the conversation.
Comments