Otto  background

Linux Hack of the Week #19: Intro to MQTT

Connect With Us

Start now, and patch, configure, and control all your endpoints in just 15 minutes.

Unless you have been typing under a rock for the past few years, you have heard about MQTT. Message Queue Telemetry Transport (MQTT) was developed in 1999 by IBM and has seen a resurgence of use thanks to the Internet of Things (IoT). MQTT uses TCP 1883 or 8883(TLS). The three main functional parts of MQTT include:

  • Sensor
  • Broker
  • Subscriber

MQTT has many advantages such as not needing to continually poll, working really well with low latency connections (think LoRa) and allows for 1 to many relationships.

The heart of MQTT is a message and these messages send topics. Topics are hierarchical strings with a maximum length of 64k. They use a path format, i.e. door/state/0 or  /drive/partition/40.

Installation

In this demonstration, we’ll use Ubuntu 18.04 with the Mosquitto package. Installation is as simple as apt-get install mosquitto for the server and apt-get mosquitto-clients for the client.tools:

Start the server process with service mosquitto start:

 

Try it!

The first step is to subscribe to all messages. Use the command mosquitto_sub -v -t ‘#’

 

In another terminal, send a message with the mosquitto_pub command, our command will use the path example/data and the message “Hello World”:

 

Now, jump back to the server terminal and watch the message on the terminal:

 

Disk Monitoring Example

As an example, we can use MQTT to monitor the disk space on a partition. We’ll use forward tics to nest the df -h command in our message. The command is mosquitto_pub -t -m “`df -h`”

 

Back in the server terminal, we see the output:

 

Conclusion

This just scratches the surface of what can be done with MQTT. I’d encourage you to pick up an IoT device like the Onion Omega and try it out. As always, feel free to let us know if you have any questions: support@automox.com.

Automox for Easy IT Operations

Automox is the cloud-native IT operations platform for modern organizations. It makes it easy to keep every endpoint automatically configured, patched, and secured – anywhere in the world. With the push of a button, IT admins can fix critical vulnerabilities faster, slash cost and complexity, and win back hours in their day. 

Grab your free trial of Automox and join thousands of companies transforming IT operations into a strategic business driver.