🛠 IoT Automation with KNOT HL9: BLE to 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
- 1x MikroTik KNOT Gateway HL9
- 1x LTE Cat 1 bis SIM card (or configured eSIM)
- 1x 802.3af/at PoE Power Supply or DC 12-57V
- 1x Compatible PoE Switch
- 1x Accessible MQTT Broker (e.g., Mosquitto on VPS)
- Compatible BLE Sensors (iBeacon, Eddystone, or custom)
- PC with SSH Terminal and Winbox
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 ``
- 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.
- 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 ``
- 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" ``
- 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 } } ``
- 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 ``
- 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
gnss-position-tracking.pyPython-Bashble-advertising-sensor.inoRouterOS-Scriptlte-failover-monitor.pyPython-Bashnand-storage-cleanup.pyPython-Bashpoe-power-status.inoRouterOS-Scriptrouteros-mqtt-telemetry.inoRouterOS Script