Mosquitto

"Bzzz"

On this page

What is Mosquitto?

Mosquitto is an open-source message broker, which means it allows different programs to exchange information in a way they can all understand.

Information is exchanged via channels, where you publish information or subscribe to to receive information.

For example, you could have a channel for every sensor in house, organised by room:

/FirstFloor/Living/Temperature
/FirstFloor/Living/Humidity
/FirstFloor/Kitchen/Temperature
etc. 
The Raspberry Pi, receiving information from various places, puts that information on the right channel so home automation software like OpenHAB can pick it up.

Install Mosquitto on a Raspberry Pi

First get the repository package signing key, import it into apt, and remove the key file again:

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
rm mosquitto-repo.gpg.key

Then make the mosquitto repository available to apt:

cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
sudo apt-get update

Now we can install the core packages (server & clients):

sudo apt-get install mosquitto mosquitto-clients

Test Mosquitto

Mosquitto is automatically started as soon as it's installed. To test, open a second terminal tab (you can do this as an extra tab in the same MobaXterm window).

Make Terminal 1 listen on the hello/world channel ("-d" means to output debug information, "-t" followed by a channel name specifies the channel):

mosquitto_sub -d -t hello/world

Have Terminal 2 publish something on the hello/world channel (same options as when subscribing, plus "-m" followed by a message):

mosquitto_pub -d -t hello/world -m "Greetings from Terminal window 2"

If all goes well, you should see the message appear in Terminal 1.

Go Back

Guides