How to install the MQTT Mosquitto broker locally on your digital picture frame's Raspberry Pi 2

How to install the MQTT Mosquitto broker locally on your digital picture frame’s Raspberry Pi

Once you discover the simplicity and power of the MQTT protocol, you will immediately start to think of all kinds of use cases for your digital picture frame.

I prefer to install the MQTT broker directly on the Raspberry that drives my digital picture frame rather than using a Cloud Service. I found this setup to be much more reliable.

In this article, I will show you how to install Mosquitto, a lightweight MQTT broker available for the Raspberry Pi. It is so undemanding, it even works on a Pi zero!

If you want to know more about MQTT, enter “MQTT” in the search bar of my website and browse through my articles. This will help to get an idea of the many use cases that MQTT offers.

Installing Mosquitto

Before installing a new software package, make sure that your Raspberry Pi is up to date by entering

sudo apt update && sudo apt upgrade -y

Now install Mosquitto

sudo apt install -y mosquitto mosquitto-clients

Using this command, Mosquitto will automatically launch after the installation. It will also automatically start at boot without having to enter any further startup commands.

You can test if the Mosquitto server is running by entering

sudo service mosquitto status
How to install the MQTT Mosquitto broker locally on your digital picture frame's Raspberry Pi 3

Hit CTRL-C to exit the result window.

Now let’s see how it works. Enter this command to make your Raspberry Pi listen to the “frame_channel”:

mosquitto_sub -h localhost -v -t frame_channel

Now open a second Terminal window connected to your Raspberry Pi and send a message to yourself:

mosquitto_pub -h localhost -t frame_channel -m "Hello Digital Picture Frame"

In your first Terminal window, you should now see “”Hello Digital Picture Frame”. If that is the case, you’re already done!

Mosquitto configuration in Pi3D image viewer

The Pi3D image viewer has a number of MQTT controlled commands to drive everything from stopping or skipping your photo playback or showing certain image information like the date of the location.

In the PictureFrame2020config.py look for these lines:

parse.add_argument("-m", "--use_mqtt",      default=True)
parse.add_argument(      "--mqtt_server",   default="localhost")
parse.add_argument(      "--mqtt_port",     default=1883, type=int)
parse.add_argument(      "--mqtt_login",    default="")
parse.add_argument(      "--mqtt_password", default="")

Make sure you enter “True” in the first line and “localhost” in the second. Unless you have created a user and a password, there is nothing else to change.

For security purposes, you may want to define a user and a password though.

Conclusion

The additional CPU load after a local install of an MQTT broker via Mosquitto locally is negligible. I didn’t even notice an increase of a single percent on my picture frame. So it makes a lot of sense to install your MQTT broker locally on your Raspberry Pi.

MQTT allows you to connect your digital picture frame with other applications and devices in an effortless way, which opens the way for countless hours of geeky stuff around Home Automation.

So give it a try and let my know what you think!

Was this post helpful?

Scroll to Top