Versions Compared

Key

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

Table of Contents

Introduction

One of the many cloud services that you can use to monitor information that is sent by an MQTT publisher is Thingsboard. This article will demonstrate how to configure both Thingsboard and RouterOS to publish the data using the MQTT protocol. RouterOS, in this scenario, is going to act as a gateway and publish the data from the RouterBoard to the Thingsboard's server. Thingsboard, in this scenario, will act as an MQTT broker (server, where data will be posted).

...

Warning

Please consider using SSL MQTT (TCP port 8883 and certificates), instead of non-SSL MQTT (TCP port 1883). If you use non-SSL MQTT, the communication between the client (MQTT publisher) and the server (MQTT broker) can be easily sniffed/packet captured, and the that will compromise authentication data (such as client ID-ids, username, usernames and passwordpasswords) will be compromised.

Thingsboard configuration

note
Info
title

In this guide, we will showcase local instance/server installation configuration, but the same principles apply to the cloud option.

...

The only difference, in this case, is the communication between the device and the server (you will only have to slightly change the MQTT broker configuration in RouterOS settings which will be shown later on).

...

  • Change the "address" to the actual IP/domain address of your ThingsBoard server;
  • Change the "certificate" selected to the actual client certificate name that you've imported;
  • Make sure to use "port=8883" (the MQTT SSL port that the server is listening to);
  • Make sure to enable "ssl=yes".

MQTT Publish

a) A quick MQTT publish test with a static value:

Code Block
languageros
/iot/mqtt/publish broker="tb" topic="v1/devices/me/telemetry" message="{\"cpu\":\"7\"}"

b) In order to publish the relevant data from the RouterOS to the Thingsboard, we will be using you can use the script shown below as a reference. The script collects the data from the RouterOS device (model name, serial number, RouterOS version, current CPU, used memory, free memory, and uptime) and publishes the message (the data) to the broker in the JSON format:

...

2 script lines should be taken into account.

:local broker "mqtt.thingsboard.cloudtb"

line, where you should specify the broker's name within the quotation marks "".

...

Copy and paste the above script into a notepad, and re-copy it again. Navigate to System>Scripts menu, add a new script there, and paste the script that is shown above (name . Name it, for example, script1).

To run the script, you can use the command line:

Code Block
languageros
/system script run script1

Verification

You can check the received/published data for the device under the "Latest telemetry" section:

...