My previous MQTT themed post walked through my setup of an MQTT broker on a TP-Link router, which serves as my local IoT communication hub. Today I’m upgrading the OpenWrt firmware along with updated mosquitto software, which is now MQTT 3.1.1 compliant!
Step 1 – Upgrade OpenWrt on router
I found and downloaded the upgrade version of the latest version of OpenWrt and reflashed the router using its web browser interface.
Step 2 – Install Mosquitto
I installed the latest version of the mosquitto library and software from the available software section of the router’s (OpenWrt) interface.
Step 3 – Test
I ran a quick test to see if the system functioned, and it did! I used mqttfx on a laptop to connect to the broker, publish and subscribe.
Step 4 – Mosquitto Configuration
The default mosquitto setup appeared to be working well however, I wanted to have a poke around and see what I could customize or tweak. I pulled up the mosquitto manual, for reference and ssh’d into my router.
It is worth noting that I also have a USB stick connected and mounted on the router, which affords me an extra 8 GB of storage (I’m thinking a potentially good location for the mosquitto.db?)
I continued by having a look at the mosquitto.conf file, which was located by default for me at /etc/mosquitto/mosquitto.conf. (I discovered this by looking through the Processes list on the OpenWrt browser page.) The default file is well commented and 819 lines, so I’ll only include my changes.
My primary areas of interest are the Persistence and Logging sections.
I changed line 423 from:
which should now save all persistent message data to disk. I also modified the path, line 433, to point to the USB stick and uncommented the filename (line 427).
I modified line 462 to set a log destination to a file on the USB stick.
log_dest file /mnt/usb/mosquitto.log
At this stage, I am interested in seeing everything, so I adjusted line 476 to log all message types.
In the security section I added a client prefix to line 504. I won’t share what that is here though 🙂 I’ve also changed the
allow_anonymous to false and pointed the
password_file to the password file I created using
mosquitto_passwd - c .There is an acess list control which I will explore in the future. For now, I reboot the router and retest the MQTT setup.