Versions Compared

Key

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


About MQTT

Fetching data from different data sources present a number of challenges. Given the numerous different standards for dataset formats it is preferred to generalize the data before it is sent to Thingsboard. Since Thingsboard have integrated possibilities for subscribing to a MQTT-broker to fetch data for it's dashboards a Mosquitto-broker was created on the Azure VM to act as a relay to Thingsboard. MQTT is a lightweight communication protocol that is used frequently in IoT-applications.

There are a few key features that make it ideal for those kind of appliications. First of all, the protocol being lightweight means it is easy to implement, and with minimized data packets which results in low network usage. Furthermore, this leads to low power usage which saves battery time. Naturally this is very important for battery-restricted devices, for example a sensor node that is only running on battery. Lastly, the protocol provides real-time data which means immediatly after the sensor has published you can subscribe to the broker and get instant update no matter where you are in the world, as long as you're connected to the internet.

 Implementations of MQTT contains clients and a broker. The clients either publish or subscribe to the broker, which stores the latest sensor-values in topics. The protocol has two commands, publish, and subscribe which is self-explanatory. An example on how the MQTT communication flow is provided below where a sensor-node which publishes temperature-data to a broker. With to clients subscribing to that data.

Mosquitto broker

Broker configuration

IP: 198.63.93.40, Port: 9999.

The standard MQTT port, 1883, is being used by Thingsboard. Hence, the broker is configured to utilize port 9999 instead. If the port needs changing this can be done in the config file located at /etc/mosquitto/conf.d/myconfig.conf. The current configuration file is showcased below.

port 9999
listener mqtt

In order to modify the config you could, for example, use nano as shown below. Save changes with Ctrl+O and exit editor with Ctrl+X.

sudo nano /etc/mosquitto/conf.d/myconfig.conf

Broker management

The broker is running as a systemd service in the Ubuntu environment, meaning it should be able to start the broker upon reboot and when it crashes. The systemd service has 4 main attributes that can be used to manage the broker. 

  • Start service:
sudo systemctl start mosquitto.service
  • Restart service
sudo systemctl restart mosquitto.service
  • Stop service
sudo systemctl stop mosquitto.service
  • Check status of service
systemctl status mosquitto.service


Running the broker in debug-mode provides you with the possibility to see the output and not run the broker as a service. This is done by the following bash-command.

sudo mosquitto -c /etc/mosquitto/mosquitto.conf




Table of Contents