Shares

How to Install Mosquitto Broker on Raspberry Pi

Shares

In this post you’re going to install the Mosquitto Broker on a Raspberry Pi.

The broker is primarily responsible for receiving all messages, filtering the messages, decide who is interested in it and then publishing the message to all subscribed clients.

There are several brokers you can use. For this blog post series, we’re going to use the Mosquitto Broker which will be installed on a Raspberry Pi.

Recommended resources:

If you like home automation and you want to build a complete home automation system, I recommend downloading my home automation course.

Let’s install the Mosquitto Broker!

Updating the Repository

To update the repository you need to import the repository package signing key:

pi@raspberry:~ $ wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
pi@raspberry:~ $ sudo apt-key add mosquitto-repo.gpg.key

Make the repository available to be installed with apt-get:

pi@raspberry:~ $ cd /etc/apt/sources.list.d/
pi@raspberrypi:/etc/apt/sources.list.d $

Then, run the following command:

pi@raspberrypi:/etc/apt/sources.list.d $ sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list

Go back to the root directory:

pi@raspberrypi:/etc/apt/sources.list.d $ cd
pi@raspberry:~ $

Finally, update apt-get information:

pi@raspberry:~ $ sudo apt-get update

Installing Mosquitto Broker

To install the Mosquitto Broker enter the next command:

pi@raspberry:~ $ sudo apt-get install mosquitto

You’ll have to type Y and press Enter to confirm the installation.

Testing Installation

Send the command:

pi@raspberry:~ $ mosquitto -v

This returns the Mosquitto version that is currently running in your Raspberry Pi. It should be 1.4 or above.

Note: sometimes the command mosquitto -v prompts a warning message saying “1484326030: Error: Address already in use”. That warning message means that your Mosquitto Broker is already running, so don’t worry about that.

Wrapping up

In the next blog post, we will experiment with Mosquitto Client to see how everything ties together with practical examples.

Like home automation? Learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino with my course: Build a Home Automation System for $100.

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Leave a Comment:

Add Your Reply