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 have previously described a solution using an external MQTT broker like CloudMQTT as the post office for your setup. However, I recently got a new router and subsequently had any issue with a port release using CloudMQTT, which meant that my frame couldn’t access the external MQTT service anymore.

So I decided that it was time to install the MQTT broker directly on the Raspberry that drives my digital picture frame.

In this article, I will show you how to install Mosquitto, a lightweight MQTT broker available amongst many other software platforms 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 my various articles, you will find instructions using CloudMQTT as a broker. If you now want to change to a locally hosted Mosquitto broker, this is what you need to change:

Previously the lines where you configure the CloudMQTT broker looked like this:

client.username_pw_set( "username" , "password" )
client.connect( "", 17905, 60)

With Mosquitto installed, you can change them to something like this:

#client.username_pw_set( "username" , "password" )
client.connect( "the-local-IP-of-your-Raspberry-Pi", 1883, 60)

Alternatively, if you are using the Bonjour service, instead of the IP you can put in your Raspberry Pi’s name followed by “.local” to make it look like this:

client.connect( "pictureframe.local", 1883, 60)

Note the port change from “17905” to “1883”.

You do not need a username or a password to publish MQTT messages, so by putting a “#” in front of the line, you are just commenting out this line.

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


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 article helpful?

Scroll to Top