routeros-mqtt-telemetry.ino

MikroTik KNOT Gateway HL9 · File : routeros-mqtt-telemetry.ino · Language : RouterOS Script · Use case : Envoyer les données du capteur de température interne vers un serveur MQTT via le réseau LTE ou Ethernet.

RouterOS v7 script reading CPU temperature and publishing JSON to an MQTT broker.

Uses native RouterOS v7 commands. Ensure the MQTT module is enabled. The script runs via the built-in scheduler. Requires active network connectivity (LTE or Ethernet).

routeros-mqtt-telemetry.ino

/system script add name="mqtt-temp" source={
:local temp [/interface wireless registration-table print detail where name=wlan1 as-value];
# Note: RouterOS v7 exposes some internal sensors via /system health
:local cpuTemp [/system health print detail where name=cpu-temp as-value];
:local payload ("{\"device\":\"HL9\",\"cpu_temp\":" . [:tostr [$cpuTemp get temp]] . "}");
/tool mqtt publish broker="mqtt.example.com" port=1883 topic="knot/hl9/status" payload=$payload username="user" password="pass";
} /system scheduler add name="mqtt-sched" interval=5m on-event=mqtt-temp

← Back to the board