Mosquitto – MQTT Broker Install

Okay, first off this is a helper for me to remember what I did to get rolling with Mosquitto. If you find it useful great and if not great. This info is based off a few Mosquitto articles on the web that I put together as what worked best for me. I did most of this research originally for my Raspberry Pi but this works well with the ODROID-C1 as well. I will post all my reference links at the bottom of this article.

Let me also state that I personally prefer to have packages that are updated by a repository that I don’t have to compile over and over every time there is an update. If you would rather have the control and compile your own version, scroll down past the instructions and click on the xAppsSoftware Blog link.

If you’re better with video tutorials follow this one from Ben with Bruh Automation:
YouTube MQTT Install

With all that said let’s get started.

To begin open your Linux Terminal.

Grab the repo key:

Add the repo key to your ODRIOD-C1:
sudo apt-key add mosquitto-repo.gpg.key

Go to your apt sources.list.d folder:
cd /etc/apt/sources.list.d/

Download the repo list for apt sources use:
# Old way
#sudo wget
sudo wget

Update your apt sources:
sudo apt update

Finally, the reason you made it this far …
sudo apt install -y libwebsockets8 mosquitto mosquitto-clients

Note: If using Python MQTT you will want to install “paho-mqtt” through pip. e.g. pip install paho-mqtt


So it might be a good idea to test all this right?!?

In your current Terminal type the following to begin your test:
mosquitto_sub -h -t '#'

Open a second / new Terminal and type the following to see if your test worked!
mosquitto_pub -h -t testTopic -m "Testing 1. 2. 3."


Want to add username / password to your MQTT Broker? Here is an example of my mosquitto.conf file:

(File: /etc/mosquitto/conf.d/mosquitto.conf)

port 1883 localhost

listener 8883 localhost
certfile /etc/letsencrypt/live/
cafile /etc/letsencrypt/live/
keyfile /etc/letsencrypt/live/

listener 9001
protocol websockets
websockets_log_level 255

listener 9002
protocol websockets
certfile /etc/letsencrypt/live/
cafile /etc/letsencrypt/live/
keyfile /etc/letsencrypt/live/

autosave_interval 10
autosave_on_changes false

allow_anonymous false
password_file /etc/mosquitto/mosquitto.pwd


Password file example:

(File: /etc/mosquitto/mosquitto.pwd)



So the password file is hashed. Here is a nice tutorial on how to hash your Mosquitto passwords. (Just don’t run the hash command twice, like I did! It will do a second hash on your hashed password!)





Reference Material a.k.a. where the real info above originated from!

xAppsSoftware Blog – Mosquitto Tutorial

Installing mosquitto on Raspberry Pi

Hardware Hacks Blog


Mosquitto Website

Mosquitto Downloads