Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

IoT package is available with RouterOS version 6.48.3. You can get it from our download page - under "Extra packages".

PropertyDescription
brokersA list of configured MQTT brokers.
connectA command that specifies, which broker to connect to.
disconnectA command that specifies, which broker to disconnect from.
publish
A command that defines the MQTT message that needs to be published.

subscribe

A command that defines MQTT topics to subscribe to.

subscriptions

A list of subscribed topics and received messages.

unsubscribe

A command that specifies, which topic to unsubscribe from.

Brokers

To add a new broker, run the following command:

...

Configurable properties are shown below:

PropertyDescription
address (IP|hostname; Default: )IP address or hostname of the broker.
auto-connect (yes | no; Default: no)When enabled, after the connection with the MQTT broker goes down/gets interrupted, RouterOS will try to re-establish the connection over and over again.
certificate (string; Default: )
The certificate that is going to be used for the SSL connection.

client-id (string; Default: )

A unique ID used for the connection. The broker uses this ID to identify the client.

keep-alive (integer:30..64800; Default: 60)

A parameter that defines the time (in seconds), after which the client should "ping" the MQTT broker that it is "alive", to ensure the connection stays ongoing. This value should be set according to MQTT broker settings.

name (string; Default: )

Descriptive name of the broker.

password (string; Default: )

Password for the broker (if required by the broker).

port (integer:0..4294967295; Default: 1883)

Network port used by the broker.

ssl (yes | no; Default: no)

Secure Socket Layer configuration.
username (string; Default: )Username for the broker (if required by the broker).

An example of adding a broker:

...

Code Block
languageros
/iot mqtt brokers print            
 0 name="my PC" address="192.168.88.33" port=1883 ssl=no client-id="test-client" auto-connect=no keep-alive=60 connected=no 

Publish

PropertyDescription
broker (string; Default: )
Select the broker, where to publish the message.
disconnect-after (yes | no; Default: no)Parameter, that ensures that the connection with the broker will be automatically disconnected after the publish message is sent.
force (yes | no; Default: yes)
If set to "yes", when the connection with the broker is not yet established ("connected=no"), and the message is attempted to be published, RouterOS will try to establish an MQTT connection with the specified broker first and then publish the message. If set to "no", RouterOS will not be able to send the message, unless the connection is already established beforehand ("connected=yes").

message (string; Default: )

The message that you wish to publish to the broker.

qos (integer:0..4294967295; Default: 0)

Quality of service parameter, as defined by the broker.

retain (yes | no; Default: no)

Whether to retain the message or to discard it if no one is subscribed to the topic. This parameter is defined by the broker.

topic (string; Default: )

Topic, as defined by the broker.

An example of publishing the message:

Code Block
languageros
/iot mqtt publish message="test-message" broker="my PC" topic="my/test/topic"

Subscribe

PropertyDescription
broker (string; Default: )
Select the broker, where to subscribe to.
force (yes | no; Default: yes)
If set to "yes", when the connection with the broker is not yet established ("connected=no"), and subscription is attempted, RouterOS will try to establish an MQTT connection with the specified broker first and then subscribe to the topic. If set to "no", RouterOS will not be able to subscribe to the topic, unless the connection is already established beforehand ("connected=yes").

qos (integer:0..4294967295; Default: 0)

Quality of service parameter, as defined by the broker.

topic (string; Default: )

Topic, as defined by the broker, where to subscribe to.

An example of a subscription:

...

Code Block
languageros
/iot mqtt subscriptions recv clear

Unsubscribe

PropertyDescription
broker (string; Default: )
Select the broker to unsubscribe from.

topic (string; Default: )

Select a topic, as defined by the broker, to unsubscribe from.

An example of unsubscribing from the broker and the topic is shown below:

Code Block
languageros
/iot mqtt unsubscribe broker="my PC" topic="my/test/topic"

...

Collecting general RouterOS statistics using a script

You can also use scripts (to automate the process). For example, you can run a script like this (copy it into a notepad and then into the script "source" field):

...

Do not forget to change the "Configuration" part of the script (topic and the broker) based on your settings.

Automating actions based on the received messages