MQTT client in routerOS
Posted: Thu May 16, 2019 3:27 pm
I created an environment in routerOS, that enables IoT-like (i.e. the server doesn't talk to the router, but the router talks to the server) operation. it works in a reasonable way, but i'd think i'd be better of with a proper MQTT client implementation in the device, that enables subscribing and posting to topics:
- performance data, state, logs, idk - so in general "a routerOS variable"
- trigger a script / feed the input of an event that is sent to a subscribed topic
i might say, this shouldn't be a big performance issue as teeny-tiny micros can accommodate one and live on, so i thought i might ask the scripting community whether it would spark some ideas/interest on someone else's side, and create a demand so the next minor release of RouterOS (or maybe #RouterOS7) will suddenly include this functionality.
my explanation for it is that i don't want to track devices, i might not will be able to talk to them (behind nat, behind firewall), but in many cases they could just talk to my server. this would also enable some sort of ZTP/ZTO environment as well.
imagine something like
and you'll be able to use a script to write a routerOS variable or just a string to a publish-mode topic:
- performance data, state, logs, idk - so in general "a routerOS variable"
- trigger a script / feed the input of an event that is sent to a subscribed topic
i might say, this shouldn't be a big performance issue as teeny-tiny micros can accommodate one and live on, so i thought i might ask the scripting community whether it would spark some ideas/interest on someone else's side, and create a demand so the next minor release of RouterOS (or maybe #RouterOS7) will suddenly include this functionality.
my explanation for it is that i don't want to track devices, i might not will be able to talk to them (behind nat, behind firewall), but in many cases they could just talk to my server. this would also enable some sort of ZTP/ZTO environment as well.
imagine something like
Code: Select all
/system script
add name=handler1 source=":log info message=\"received: $mqtt_input on $mqtt_topic\""
/mqtt brokers
add name=broker1 server=fqdn.of.the.broker port=6969
add name=broker2 server=this.is.another.broker port=1183
/mqtt topics
add name=topic1 broker=broker1 mode=publish topic=topicname
add name=topic2 broker=broker2 mode=subscriber topic=controller script=handler1
Code: Select all
/mqtt post topic="topic1" message=$myvar