MQTT is a messaging technology for machine-to-machine communication that’s lightweight and relatively simple to implement on pretty much any device. In my first post on MQTT I covered the basics and background of the protocol and threatened to follow up with a discussion of Mosquitto, a free, open source MQTT server (the MQTT developers no longer call them “brokers”) that’s one of the most widely used messaging platforms in the Internet of Things world. Being a man of my word, here goes …
The Mosquitto broker (apparently the Mosquito developers and MQTT developers do not see eye-to-eye on terminology) is part of the Eclipse IoT Working Group, “an industry collaboration of companies who invest and promote an open source community for IoT.” Mosquito currently supports MQTT versions 3.1 and 3.1.1 and support for the proposed MQTT v5, which introduces scalability and protocol improvements is under way.
Installing Mosquitto is straightforward on most systems including the Raspberry Pi under Raspbian. My test setup for IoT experiments is based on Debian virtual machines which I built on a QNAP TS-871T under QNAP’s Virtualization Station. While there are a number of prebuilt Debian VM appliances available including some with Mosquitto installed, I prefer to use a VM I’ve created so that I know that it’s a minimal base system that I can easily rebuild if (when) I mess it up and that there’s nothing in the VM that I don’t know about.
QNAP HTML-based remote desktop showing the installation of Mosquitto on a Debian VM running under QNAP’s Virtualization Station.
Installing Mosquitto under Debian 8.7 is simple. On the command line enter:
sudo apt-get update
sudo apt-get install mosquitto
And, bam! Mosquitto is installed and, should the gods smile on you, it will be up and running. That is, up and running if you’re on vanilla Debian. For other configurations and operating systems you may have to enter:
mosquitto -c /etc/mosquitto/mosquitto.conf &
Want to find Mosquitto’s process ID (pid)? Mosquitto will be running as the user mosquitto
so you’ll need to enter:
ps auxm | grep mosquitto
Starting, restarting, and stopping Mosquitto?
service mosquitto <operation>
Where <operation>
is start
, restart
, or stop
.
Configuring Mosquitto is a little more complicated than installation. Okay, make that a lot more complicated. The default configuration file can be found at/etc/mosquitto/mosquitto.conf
although if the file doesn’t exist, Mosquitto will assume the same values you’ll find in the default configuration file. There are lots of options and parameters to set and if you’re not on a secured network (and, some might argue, even if you are) you should at least configure Mosquitto to require subscribers and publishers to authenticate and for your MQTT traffic to run over TLS (see MQTT TLS Security – Mosquitto Broker Configuration for a tutorial on how to lock down your installation).
For the purposes of this series we’ll stick with the default unsecured configuration. So now we’ve got a basic installation of Mosquitto running, we need to test it, which we’ll do in the next installment.
Comments? Thoughts? Drop me a line or comment below then follow me on Twitter and Facebook. And sign up for my new newsletter!