Easy Raspberry basics: Project 07a Install and Run Mosquitto Broker on Raspberry PI 3 model B board

of Acoptex.com in Raspberry Pi 3

Raspberry basics: Project 07a

Project name: Install and Run Mosquitto Broker on Raspberry PI 3 model B board

Tags: Raspberry, Raspberry PI 3 model B board, Mosquitto Broker, Mosquitto Client

 In this project, you need these parts :

1.Raspberry PI 3 model B 1 pc

2. Micro SD card and SD card adapter 1 pc

3. Micro USB power supply (2.1 A, max 2.5 A) 1 pc

4. USB keyboard 1 pc

5. USB mouse 1 pc

6. TV or PC monitor 1 pc


We will learn how to to install the Mosquitto Broker on Raspberry PI 3 model B board.

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. In our Home Automation projects we use the Mosquitto Broker installed on a Raspberry Pi 3.

Understanding the Raspberry PI 3 model B

The Raspberry Pi 3 is the third-generation Raspberry Pi. It replaced the Raspberry Pi 2 Model B in February 2016.


  • Quad Core 1.2GHz Broadcom BCM2837 64bit CPU
  • 1GB RAM
  • BCM43438 wireless LAN and Bluetooth Low Energy (BLE) on board
  • 40-pin extended GPIO
  • 4 USB 2 ports
  • 4 Pole stereo output and composite video port
  • Full size HDMI
  • CSI camera port for connecting a Raspberry Pi camera
  • DSI display port for connecting a Raspberry Pi touchscreen display
  • Micro SD port for loading your operating system and storing data
  • Upgraded switched Micro USB power source up to 2.5A

Signals and connections of the Raspberry PI 3 model B

Step by Step instruction

We recommend using a high-performance SD card for increased stability as well as plugging your device into an external display to see the default application booting up.

1. Installing Mosquitto Broker on Raspbian OS

We assume that you have Windows 10 installed on your PC and Raspbian OS installed on your Raspberry PI 3 board.

  1. Insert your micro SD card with Raspbian OS to Raspberry Pi 3 board.
  2. Connect the TV or PC monitor Display port (HDMI Port) to your Raspberry PI 3 board HDMI Port (HDMI cable required).
  3. Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1,  etc).
  4. Plug in your USB mouse and USB keyboard to Raspberry PI 3 board USB ports.
  5. Get connected. Connect an Ethernet cable to 10/100 LAN port of Raspberry Pi 3 or plug in WiFi adapter (see the list of supported here) to USB port of Raspberry Pi 3.
  6. Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
  7. The Raspberry PI desktop will start up.
  8. Open Terminal window and type the command: sudo apt-get update
  9. Then type the command: sudo apt-get upgrade
  10. Press Y button on the keyboard when you see the message Do you want to continue?Y/n
  11. Enter the command to install the Mosquitto Broker: sudo apt install -y mosquitto mosquitto-clients

  12. Enter the command to make Mosquitto auto start on boot up: sudo systemctl enable mosquitto.service

2. Testing Mosquitto Broker and MQTT Client

  1. Type the command: mosquitto -v

  2. This returns the Mosquitto version that is currently running in your Raspberry Pi. It should be 1.4.10 or above.
  3. If 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, don’t worry about that.
  4. You will need your Raspberry Pi 3 IP address to use Mosquitto broker later on your DIY projects. Type the command: hostname -I Our Raspberry Pi 3 IP address is Save your Raspberry Pi IP address because you will need it in future projects.
  5. After installing MQTT Broker, I recommend installing an MQTT Cllient to test the Broker installation and publish sample messages.
    The next command shows how to install MQTT Mosquitto Client:
    After installing MQTT Broker we will install an MQTT Cllient to test the Broker installation and publish sample messages. Type the command: sudo apt-get install mosquitto-clients to install MQTT Mosquitto Client.
  6. Enter the command to run Mosquitto on background as a daemon: mosquitto -d

  7. You are now subscribed to a topic called testTopic.
  8. Type this command to publish a sample message to testTopic, open another terminal Window #2: mosquitto_pub -d -t testTopic -m "Hello world!"
  9. The message Hello World! is received in Window #1.
  10. Open a new terminal Window #3 and run this command to subscribe to testTopicmosquitto_sub -d -t testTopic

  11. Publish the Hello World! message in Window #2 with this command: mosquitto_pub -d -t testTopic -m "Hello world!"
  12. Since two clients are subscribed to testTopic, they will both receive Hello world! message.
  13. This simple example shows how MQTT works and how your devices (for example: ESP8266 ESP-12E or ESP32) could be subscribed to the same topic to receive messages or a device could publish messages to multiple devices. 


We have learnt how to to install the Mosquitto Broker on Raspberry PI 3 model B board.


  • No libraries needed in this project


  • No sketches needed in this project

Other projects of Acoptex.com
Easy Basics: Project 101a Ai Thinker A9G GPRS GPS development board of Acoptex.com, Not selected 23-11-2019
Easy Basics: Project 100a Ai Thinker A9 GSM GPRS development board of Acoptex.com, Not selected 22-11-2019

Published at 14-09-2018
Viewed: 1316 times