LoRa / LoRaWAN Integration with ASI Biont: From Raw Radio Packets to Chat‑Driven Telemetry and Alerts

Why Your LoRaWAN Network Needs an AI Agent

LoRaWAN is the de‑facto standard for low‑power, long‑range IoT telemetry. A single gateway can cover kilometers, sensors run on coin cells for years, and protocols like the LoRaWAN 1.0.4 specification (LoRa Alliance, 2023) ensure interoperability. Yet, every operator I’ve met hits the same wall: the data lands in a network server (TTN, ChirpStack, LoRa Cloud), but turning that into actionable alerts or a readable dashboard requires custom glue logic, API integrations, and constant tweaking.

That’s where ASI Biont changes the game. Instead of writing a separate microservice for every sensor, you connect the AI agent directly to your LoRaWAN infrastructure. ASI Biont speaks to devices over COM ports (RS‑232/RS‑485 via the Hardware Bridge), MQTT, Modbus/TCP, HTTP/WebSocket, OPC‑UA, and a dozen other protocols — all through a normal chat dialog. No management panels, no “add device” wizards. Just describe your setup in plain English and the agent generates the integration code in seconds.

This article is a practical guide for connecting LoRaWAN devices to ASI Biont, with real code, wiring schematics, and the pitfalls I’ve hit (and fixed) along the way.

How ASI Biont Connects to LoRaWAN

LoRaWAN is an IP‑agnostic radio protocol. The physical layer is LoRa (Chirp Spread Spectrum), but the gateway bridges packets to a network server via Ethernet, Wi‑Fi, or cellular. There are two realistic integration points for ASI Biont:

Integration Point Method When to Use
LoRa gateway serial console COM port via Hardware Bridge (bridge.py) You have a local gateway (RAK, Dragino, Kerlink) with a serial debug port that prints received frames, or you use a USB‑connected LoRa concentrator like SX1302.
Network server MQTT output paho‑mqtt over TCP You use TTN, ChirpStack, or The Things Industries, and want to consume decoded sensor data (JSON/CayenneLPP) directly. This is the most common production setup.

Because this article lives in the “COM port and serial interfaces” category, I’ll focus on the serial path, but also show the MQTT alternative — because you’ll likely need both.

The Hardware Bridge for Serial LoRa Gateways

ASI Biont connects to serial ports through a small helper called bridge.py. You download this file from the ASI Biont dashboard — not from GitHub, it’s tied to your account token. Launch it on the machine that has the gateway’s USB/serial port:

python bridge.py --token=XXX --ports=COM3 --baud=115200 --rate=10

This exposes the serial port as a transparent channel. From that point, the AI agent can send arbitrary commands through industrial_command(). For example, to read a line from the gateway’s serial output:

response = industrial_command(
    protocol="serial",
    command="read_line",
    port="COM3",
    timeout=2
)

Where does industrial_command() come from? It’s a built-in function in the ASI Biont execution environment. You don’t need to install a library — it exists only inside the AI’s Python sandbox.

MQTT: The Ubiquitous LoRaWAN Backbone

Most LoRaWAN servers publish device messages to MQTT. TTN v3 uses topics like v3/<app-id>/devices/<dev-eui>/up. ASI Biont can subscribe to these topics using its native MQTT client (paho‑mqtt). You just tell the agent your app ID, device EUI, and MQTT credentials — it writes the subscription code for you.

Practical Scenario: Warehouse Temperature Monitoring via LoRaWAN + Telegram

Let’s make this concrete. You have a Dragino LHT65 sensor (temp & humidity) connected to a RAK7249 gateway, and the gateway is configured to push payloads to TTN. You want to:

  • Monitor temperature and humidity every 15 minutes.
  • Get an instant Telegram alert when the temperature exceeds 30°C.
  • Be able to ask the AI agent: “What was the average temperature last night?”

Step 1: Tell ASI Biont About Your Setup

In the ASI Biont chat, you type:

Connect to my TTN app over MQTT. App ID: warehouse-mon, Device EUI: A84041FFFF012345. Payload is CayenneLPP. Subscribe to uplink messages. Parse temperature and humidity. Send Telegram alerts when temp > 30.

The agent responds with a plan, then writes and executes a Python script. Here’s what that script looks like (AI‑generated, but I’ve cleaned it up for readability):

import paho.mqtt.client as mqtt
import json, requests, time, threading

TELEGRAM_BOT_TOKEN = "123456:ABC-DEF1234"
TELEGRAM_CHAT_ID = "-456789012"

THRESHOLD_TEMP = 30.0

def send_telegram(text):
    requests.post(
        f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage",
        json={"chat_id": TELEGRAM_CHAT_ID, "text": text}
    )

def parse_cayenne(data):
    # Minimal CayenneLPP decoder for temperature (0x67) and humidity (0x68)
    # See https://developers.mydevices.com/cayenne/docs/lora/ for spec
    i = 0
    values = {}
    while i < len(data):
        channel = data[i]
        type_code = data[i+1]
        if type_code == 0x67:  # Temperature, 2 bytes
            raw = int.from_bytes(data[i+2:i+4], 'big', signed=True)
            values['temperature'] = round(raw * 0.1, 2)
            i += 4
        elif type_code == 0x68:  # Relative humidity, 1 byte
            values['humidity'] = data[i+2]
            i += 3
        else:
            i += 2  # skip unknown channels
    return values

def on_message(client, userdata, msg):
    payload = json.loads(msg.payload)
    decoded = payload.get("uplink_message", {}).get("decoded_payload") or {}
    if not decoded:
        # If TTN hasn't decoded it, try raw bytes
        raw = payload["uplink_message"]["frm_payload"]
        decoded = parse_cayenne(bytes.fromhex(raw))
    temp = decoded.get("temperature")
    hum = decoded.get("humidity")
    if temp is not None:
        print(f"[{time.ctime()}] Temp: {temp}°C, Humidity: {hum}%")
        if temp > THRESHOLD_TEMP:
            send_telegram(f"🚨 Warehouse #3 TOO HOT: {temp}°C!")

client = mqtt.Client()
client.username_pw_set("warehouse-mon", "ttn-account-v2.XXXXXXXX")
client.on_message = on_message
client.connect("eu1.cloud.thethings.network", 1883, 60)
client.subscribe("v3/warehouse-mon/devices/a84041ffff012345/up")
client.loop_forever()

Notice a few things:
- The AI used requests.post directly to Telegram’s API — no magic send_telegram() helper that doesn’t exist.
- The script runs as a background task on the ASI Biont server, so loop_forever() is fine. I specifically asked for a long‑running subscription.
- If your payload isn’t CayenneLPP, the agent can parse raw hex bytes from your sensor’s datasheet. I’ve done this with an MDA100 analog sensor and a custom byte‑order quirk — the agent figured it out from the datasheet I pasted into chat.

Step 2: Chat‑Driven Data Collection and Control

Once the script is live, you interact with it conversationally:

  • “What’s the current temperature?” — the agent queries the last cached value from its internal state.
  • “Send me the last 24 hours of humidity” — the agent reads historical data if you’ve stored it in a database (ASI Biont can append to SQLite or PostgreSQL).
  • “Turn on the HVAC in zone 2 if temp > 28” — the agent writes a command that sends a LoRaWAN downlink through TTN’s MQTT topic. For a Dragino LHT65, that means setting the relay on/off via a field in the payload.

Here’s an example of a downlink command the AI might generate for a LoRaWAN‑connected relay:

import paho.mqtt.publish as publish
import json

downlink_payload = json.dumps({
    "downlinks": [{"f_port": 2, "frm_payload": bytes([1]).hex(), "priority": "HIGH"}]
})
publish.single(
    "v3/warehouse-mon/devices/a84041ffff012345/down/push",
    payload=downlink_payload,
    hostname="eu1.cloud.thethings.network",
    auth={"username": "warehouse-mon", "password": "ttn-account-v2.XXXXXXXX"}
)

No need to open the TTN console, no manual payload formatting. Just ask.

Alternative: Direct Serial Connection to a LoRa Concentrator

If your LoRa gateway is just a USB concentrator (like the RAK2245) or a Digi XBee LoRa module in serial mode, you can connect it via COM port instead of MQTT. This is useful when you’re in the field and don’t want a cloud dependency. The Hardware Bridge reads raw data from the module, and the agent parses the serial frame (typically LoRaWAN packet bytes or a gateway’s JSON input from .dat files).

Example: A RAK2287 concentrator on /dev/ttyACM0 at 115200 baud. In chat, you say:

Connect to the concentrator on /dev/ttyACM0, baud 115200. I’m using the RAK wireless serial library. Decode the packet logs and show me CRC errors.

The agent launches the bridge with --ports=/dev/ttyACM0 --baud=115200 and then uses industrial_command() to read lines:

for _ in range(10):
    line = industrial_command(protocol="serial", command="read_line", port="/dev/ttyACM0", timeout=5)
    if line:
        print(line)

It then identifies bad packets by checking the CRC/AES metadata and prints a summary. This works because ASI Biont’s execute_python runs arbitrary Python code, so it can also import pyserial directly if you’re running a custom bridge on your own host.

The “Connect Anything” Philosophy

The beautiful part is that ASI Biont doesn’t have a predefined list of supported LoRaWAN devices. Instead, the AI agent writes a unique integration script each time. You just provide the parameters:

  • Port (COM3) or MQTT endpoint
  • Baud rate / QoS / credentials
  • Payload format (CayenneLPP, JSON, raw hex)
  • Your business rules (alerts, thresholds, statistics)

The agent literally generates Python code using pyserial, paho‑mqtt, pymodbus, aiohttp, or opcua‑asyncio on the spot. So if you’re using a generic 4‑20mA LoRaWAN transmitter that isn’t in any vendor list, you can still connect it by pasting the datasheet table into the chat. I did this for a soil moisture sensor from a local manufacturer — the AI understood the scaling formula 0–1023 → 0–100% and correctly converted it.

Traditional vs. ASI Biont Integration

Aspect Traditional ASI Biont
Time to first alert Days (write parser, set up MQTT, code alert) Minutes (describe setup in chat)
Code ownership You maintain custom Python/Node service AI generates and updates the script live
New device support Wait for SDK/plugin Describe the datasheet, done
Debugging Manually check logs Ask “why isn’t my sensor updating?” and it adds diagnostics
Payload changes Refactor code, redeploy Say “the vendor changed payload to little‑endian” and it re-writes the parser

Pitfalls I’ve Learned the Hard Way

  • Don’t use while True in execute_python — it times out after 30 seconds. For continuous monitoring, ask the agent to run a background MQTT subscription or use the bridge’s --rate parameter for periodic polling.
  • Telegram bot messages are sent via a plain HTTP POST — use requests.post. A common mistake is to try send_telegram() which doesn’t exist in ASI Biont functions.
  • CayenneLPP has a specified byte order — the AI may guess wrong initially. Always provide a sample payload. I paste a raw hex frame from the TTN console and the agent decodes it correctly.
  • MQTT topic authentication — TTN v3 uses one API key for both MQTT and REST. Use the tti key with the Right_IoT_Controller right. The agent knows this, but double‑check you didn’t give it a read‑only key if you need downlinks.
  • LoRaWAN downlink duty cycle — you can’t send commands every second. The agent can add a cooldown timer if you ask.

Real‑World Use Cases Beyond Warehouses

  • Smart Agriculture: Soil moisture, temperature, and leaf wetness sensors across a farm. The AI correlates rainfall data (via an open weather API) with sensor readings and suggests irrigation schedules. Farmers just ask in chat: “Should I water tomorrow?”
  • Container Tracking: LoRaWAN GPS trackers on cargo containers. The agent calculates average transit time, alerts when a container opens outside designated areas, and generates a weekly PDF report.
  • Energy Monitoring: Non‑invasive current transformers sending data over LoRaWAN. The AI identifies unusual spikes and traces them to specific timestamps, which you can then correlate with production events.

Conclusion: Stop Gluing, Start Asking

LoRaWAN provides the radio infrastructure, but converting raw packets into decisions is the hard part. ASI Biont removes the coding bottleneck by letting you describe the integration in natural language. Whether you use a serial LoRa gateway or a cloud network server, the agent writes the parser, sets up the alerts, and answers your questions about the data — all in seconds, not development sprints.

I use this for our shop floor’s temperature monitoring and it’s been rock‑solid for three months. The only maintenance I do is “increase the alert threshold to 32°C” and the agent handles the rest.

Ready to connect your LoRaWAN devices? Head over to asibiont.com and describe your setup in chat. No dashboards, no waiting for SDKs — just a working integration from minute one.

← All posts

Comments