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 Mosquitto.org repo key:
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

Add the Mosquitto.org 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 Mosquitto.org repo list for apt sources use:
# Old way
#sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.list
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list

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 127.0.0.1 -t '#'

Open a second / new Terminal and type the following to see if your test worked!
mosquitto_pub -h 127.0.0.1 -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/example.bracketninja.com/cert.pem
cafile /etc/letsencrypt/live/example.bracketninja.com/chain.pem
keyfile /etc/letsencrypt/live/example.bracketninja.com/privkey.pem

listener 9001
protocol websockets
websockets_log_level 255

listener 9002
protocol websockets
certfile /etc/letsencrypt/live/example.bracketdojo.com/cert.pem
cafile /etc/letsencrypt/live/example.bracketdojo.com/chain.pem
keyfile /etc/letsencrypt/live/example.bracketdojo.com/privkey.pem

autosave_interval 10
autosave_on_changes false

allow_anonymous false
password_file /etc/mosquitto/mosquitto.pwd

 

Password file example:

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

my_mqtt_username:$7$EWCEeFCDgFEDDtXFjERFnDSyDDyyFDdsSXsdsDsBGIJZNrYTMpwbEUFxZoX9SuIzodW/wIn1U7y7ivlXDqJw==

 

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!)

http://www.steves-internet-guide.com/mqtt-username-password-example/

 

 

 

 


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


xAppsSoftware Blog – Mosquitto Tutorial

Installing mosquitto on Raspberry Pi

Hardware Hacks Blog

http://c-mobberley.com/wordpress/2013/10/06/mosquitto-the-open-source-mqtt-broker-that-can-be-installed-on-the-raspberry-pi/

 

Mosquitto Website

https://mosquitto.org/

Mosquitto Downloads

https://mosquitto.org/download/