Random Nerd Tutorials
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.

mqtt-broker

There are several brokers you can use. In our Home Automation projects we use the Mosquitto Broker installed on a Raspberry Pi.

Prerequisites

Before continuing with this tutorial

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

After having your Raspberry Pi board prepared with Raspbian OS, you can continue with this tutorial. Let’s install the Mosquitto Broker.

Installing Mosquitto Broker on Raspbian OS

Open a new Raspberry Pi terminal window:

To install the Mosquitto Broker enter these next commands:

pi@raspberry:~ $ sudo apt update
pi@raspberry:~ $ sudo apt install -y mosquitto mosquitto-clients

You’ll have to type Y and press Enter to confirm the installation. To make Mosquitto auto start on boot up enter:

pi@raspberry:~ $ sudo systemctl enable mosquitto.service

Testing Installation

Send the command:

pi@raspberry:~ $ mosquitto -v
cloud-download

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

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

Raspberry Pi IP Address

To use Mosquitto broker later on your projects, you’ll need your Raspberry Pi IP address. To retrieve your Raspberry Pi IP address, type the next command in your Terminal window:

pi@raspberry:~ $ hostname -I

In our case, the Raspberry Pi IP address is 192.168.1.144. Save your Raspberry Pi IP address because you’ll need it in future projects.

Testing Mosquitto Broker and MQTT Client

After installing the Mosquitto broker, you should test you installation. You can follow the next tutorial:

Wrapping up

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.


MicroPython Programming with ESP32/ESP8266 eBook

Learn how to program the ESP boards with MicroPython, including projects, tips, and tricks! The registrations are open for a limited time, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Registrations are open for "MicroPython Programming with ESP32 and ESP8266" eBook