🛠 IoT Automation with KNOT HL9: BLE to MQTT

MikroTik KNOT Gateway HL9 · avance · Configurez la passerelle KNOT HL9 pour capturer des annonces Bluetooth Low Energy et les transmettre en temps réel via MQTT.

Objectifs

This advanced tutorial aims to configure the MikroTik KNOT Gateway HL9 as an autonomous IoT collection node. The goal is to capture Bluetooth Low Energy (BLE) advertisement packets, filter them locally to reduce bandwidth, and publish them to an MQTT broker via LTE or Ethernet connection. This architecture enables robust outdoor asset tracking, leveraging Wi-Fi HaLow for management if needed, but prioritizing BLE for sensor data collection.

Required Equipment

Steps

Connect the board via Ethernet/PoE. Access RouterOS v7 via Winbox or SSH. Update the firmware to the latest stable version to ensure stability of the Quectel EG800Q module and Morse Micro SoC. ``bash /system package update install ``

  1. Connection and Update

Configure the LTE interface for data transmission. Ensure the APN is correct for your operator. ``bash /interface lte set [find name=lte1] apn="internet" /ip address add address=192.168.88.1/24 interface=lte1 `` Note: If using Ethernet, configure interface ether1 with DHCP or static IP.

  1. Backhaul Network Configuration (LTE)

Enable the Bluetooth 5.1 LE module for passive advertisement detection. Set mode to "scan" to minimize consumption. ``bash /interface bluetooth set [find name=bluetooth1] mode=scan ``

  1. Enable BLE Scanner

Define connection parameters to your MQTT broker. Use TLS to secure exchanges on public networks. ``bash /tool mqtt set [find name=mqtt1] broker="mqtt.example.com" port=8883 user="user" password="pass" tls="yes" ``

  1. MQTT Stream Configuration

Create a script that reads detected BLE data and formats it as JSON for MQTT. This script runs in the background. ``bash /system script add name=ble_to_mqtt source={ :local bleData [/interface bluetooth get [find name=bluetooth1] scan-results] :foreach item in=$bleData do={ :local payload "$($item->mac) : $($item->rssi)" /tool mqtt publish topic="knot/ble/data" message=$payload } } ``

  1. Create Transfer Script

Schedule the script execution every 10 seconds for near-real-time collection. ``bash /system scheduler add name=ble_poll interval=10s on-event=ble_to_mqtt ``

  1. Automate Scheduling

Verification

Check that the script executes without errors in the logs. On your MQTT broker, subscribe to the knot/ble/data topic with a client like MQTTX or Mosquitto Sub. You should see the MAC addresses and RSSI of nearby BLE sensors appear. Also verify that the LTE connection remains active via /interface lte print.

Further Reading

Consider using Wi-Fi HaLow 915 MHz to create a mesh network of KNOT gateways if deploying multiple units on a large agricultural site. You can also integrate more complex filtering rules in the script to transmit only specific sensors, thereby reducing LTE data consumption.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials