Simple MQTT Borker Setup on a Raspberry Pi

Home / Simple MQTT Borker Setup on a Raspberry Pi

This is the project page for the corresponding video on YouTube


The images can be found here

The SD card writing tool which also writes the boot sectors can be downloaded from here:


To install the broker you need to run the two following lines from the terminal on your raspberry:

sudo apt-get update
 sudo apt-get install mosquitto

The IP address can be determined by typing the command:


To add users and passwords you need to got to the directory:

cd /etc/mosquitto

There you can create a password file by adding the first user like this:

sudo mosquitto_passwd -c passwordfile luni

Appending another user to an existing password file can be done like this:

sudo mosquitto_passwd -b passwordfile user password

Removing a user from the file is done like this:

sudo mosquitto_passwd -D passwordfile user

Anonymous access has to be deactivated an the password file has to be added in the mosquitto.conf:

allow_anonymous false
password_file /etc/mosquitto/passwordfile

In Raspbian there is the nano editor pre-installed so you can open the file like this:

sudo nano mosquitto.conf

After adding the two lines from above you can exit nano by pressing Ctrl+O and Enter to save the changes ans Ctrl-X to quit.

To get a fixed IP address you need to configure your DHCP server on your router.
You simply need to add the MAC address of the raspberry with the IP you like.
Sorry no detailed steps here since every router is different. The manual might help.


There are two Mongoose OS apps mentioned which can be downloaded from this repository:

One is a simple MQTT test. It is one code ¬†which let’s two programmed nodes decide which one of these are Ping and which Pong and then they start to play.

The Main Switch app is an update of an older projects. It switches pin D4 in the WeMos over MQTT.

Mongoose OS can be found here:

Android App

The used MQTT App on my Android phone was MQTT Dash

This app is missing widgets but seem to support even images.. Not sure if I’ll stick to it as we proceed in the series.


Raspberry Pi on Ebay:

…and on Amazon:

These Links are supporting my channel at no extra cost to you.