Simple MQTT Broker Setup on a Raspberry Pi

This is the project page for the corresponding video on YouTube

Links

The images can be found here

https://www.raspberrypi.org/downloads/raspbian/

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

https://etcher.io/

Setup

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:

ifconfig

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.

Code

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

https://github.com/bitluni/MongooseApps

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:

https://mongoose-os.com/

Android App

The used MQTT App on my Android phone was MQTT Dash

https://play.google.com/store/apps/details?id=net.routix.mqttdash

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.

Parts

Raspberry Pi on Ebay:
http://ebay.to/2yjS5Dc

…and on Amazon:

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