HiveMQ is a cloud-service managed by a third-party, and while this is great, it has some drawbacks. In this tutorial we are going to setup our own MQTT broker using a Raspberry Pi and Mosquitto, an open-source mqtt broker.

Install Mosquitto

You will want to be logged in to the raspberry pi server either directly or via ssh to set up the MQTT broker. Once you are logged in, install Mosquitto.

sudo apt-get install -y mosquitto mosquitto-clients

If all goes well, the mosquitto should be actively running as a system service in the background.

Setup an authorized user

By default, Mosquitto allows anonymous users to connect and publish/subscribe to topics. We want to disable that and provide authorized user accounts. This will help establish new users into the Maker Exchange Network as well as provide some baseline level of security on the system.

Create a new user account by running the following command:

sudo mosquitto_passwd -c /etc/mosquitto/passwd <username>

Running the mosquitto_passwd will prompt you to enter a password for that user. This will be done by the system administrator and provided to the user.

Configure Mosquitto

To prevent anonymous users from accessing the broker and link our newly created account, we need to modify the configuration file. You can edit this file by running the following command:

sudo nano /etc/mosquitto/mosquitto.conf

Once open in the terminal text editor, add the following two lines to the bottom of the file.

password_file /etc/mosquitto/passwd
allow_anonymous false

Save and exit out of the file.

Restart Mosquitto

In order to have these changes take place, we need to restart the mosquitto service.

sudo systemctl restart mosquitto

Test Broker