member
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
General
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.
Specification:
- 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.
- Insert your micro SD card with Raspbian OS to Raspberry Pi 3 board.
- Connect the TV or PC monitor Display port (HDMI Port) to your Raspberry PI 3 board HDMI Port (HDMI cable required).
- Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1, etc).
- Plug in your USB mouse and USB keyboard to Raspberry PI 3 board USB ports.
- 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.
- Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
- The Raspberry PI desktop will start up.
- Open Terminal window and type the command: sudo apt-get update
- Then type the command: sudo apt-get upgrade
- Press Y button on the keyboard when you see the message Do you want to continue?Y/n
- Enter the command to install the Mosquitto Broker: sudo apt install -y mosquitto mosquitto-clients
- Enter the command to make Mosquitto auto start on boot up: sudo systemctl enable mosquitto.service
2. Testing Mosquitto Broker and MQTT Client
- Type the command: mosquitto -v
- This returns the Mosquitto version that is currently running in your Raspberry Pi. It should be 1.4.10 or above.
- 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.
- 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 192.168.0.121. Save your Raspberry Pi IP address because you will need it in future projects.
-
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.
- Enter the command to run Mosquitto on background as a daemon: mosquitto -d
- You are now subscribed to a topic called testTopic.
- Type this command to publish a sample message to testTopic, open another terminal Window #2: mosquitto_pub -d -t testTopic -m "Hello world!"
- The message Hello World! is received in Window #1.
- Open a new terminal Window #3 and run this command to subscribe to testTopic: mosquitto_sub -d -t testTopic
- Publish the Hello World! message in Window #2 with this command: mosquitto_pub -d -t testTopic -m "Hello world!"
- Since two clients are subscribed to testTopic, they will both receive Hello world! message.
- 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.
Summary
We have learnt how to to install the Mosquitto Broker on Raspberry PI 3 model B board.
Library
- No libraries needed in this project
Sketch
- No sketches needed in this project
Other projects of Acoptex.com










jobs.viewed