Eclipse Mosquitto™ is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for “Internet of Things” messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino. And I will show you how to install Mosquitto to RaspberryPi
- SSH into your Raspberry Pi. Now, you need to add the Mosquitto repository. Enter the following commands:
sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key sudo apt-key add mosquitto-repo.gpg.key sudo rm mosquitto-repo.gpg.key
- Next, make the repository available to apt-get. First we need to change to the apt sources list directory:
cd /etc/apt/sources.list.d/
- Now install the packages list for your Raspbian.
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
- Now update apt information and install Mosquitto.
sudo apt-get update sudo apt-get install mosquitto mosquitto
- Next we can install the three parts of Mosquitto proper.
- mosquitto – the MQTT broker (or in other words, a server)
- mosquitto-clients – command line clients, very useful in debugging
- python-mosquitto – the Python language bindings
sudo apt-get install mosquitto mosquitto-clients python-mosquitto
- Now the broker is immediately started. Since we have to configure it first, stop it by command:
sudo /etc/init.d/mosquitto stop
- We need to set up the configuration file. The configuration files is located at /etc/mosquitto. Open the config file:
sudo nano /etc/mosquitto/mosquitto.conf
File should look like this:# Place your local configuration in /etc/mosquitto/conf.d/ # # A full description of the configuration file is at # /usr/share/doc/mosquitto/examples/mosquitto.conf.example pid_file /var/run/mosquitto.pid persistence true persistence_location /var/lib/mosquitto/ log_dest file /var/log/mosquitto/mosquitto.log include_dir /etc/mosquitto/conf.d
Now replace “log_dest file /v…” line with “log_dest topic”. And add following 6 lines:
log_type error log_type warning log_type notice log_type information connection_messages true log_timestamp true
Now the file should look like this:
# Place your local configuration in /etc/mosquitto/conf.d/ # # A full description of the configuration file is at # /usr/share/doc/mosquitto/examples/mosquitto.conf.example pid_file /var/run/mosquitto.pid persistence true persistence_location /var/lib/mosquitto/ log_dest topic log_type error log_type warning log_type notice log_type information connection_messages true log_timestamp true include_dir /etc/mosquitto/conf.d
- Start the mosquito server:
sudo /etc/init.d/mosquitto start
- Test your installation by opening 2 two terminal windows to the first insert:
mosquitto_sub -d -t hello/world
- And to the second window insert:
mosquitto_pub -d -t hello/world -m "Hello from Terminal window 2!"
- When you have done the second statement you should see this in the Terminal 1 window:
~ $ sudo mosquitto_sub -d -t hello/world Client mosqsub/3014-LightSwarm sending CONNECT Client mosqsub/3014-LightSwarm received CONNACK Client mosqsub/3014-LightSwarm sending SUBSCRIBE (Mid: 1, Topic: hello/world, QoS: 0) Client mosqsub/3014-LightSwarm received SUBACK Subscribed (mid: 1): 0 Client mosqsub/3014-LightSwarm received PUBLISH (d0, q0, r0, m0, 'hello/world', ... (32 bytes)) Greetings from Terminal window 2
On Linux version 4.4.50/ Raspbian v. 8 (jessie) and mosquitto MQTT v3.1 the mosquitto will start on boot automatically.
At step 4 I am getting:
pi@raspberrypi:/etc/apt/sources.list.d $ sudo apt-get install mosquitto mosquitto
Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
mosquitto : Depends: libssl1.0.0 (>= 1.0.1) but it is not installable
Depends: libwebsockets3 (>= 1.2) but it is not installable
E: Unable to correct problems, you have held broken packages.
Thank you for your comment.
What version of Raspbian are you using ?
Did you do “apt-get update” ? The update should contain the mosquitto repos:
pi@raspberrypi:/etc/apt/sources.list.d $ sudo apt-get update
Get:1 http://repo.mosquitto.org jessie InRelease [3884 B]
Hit http://mirrordirector.raspbian.org jessie InRelease
Hit http://archive.raspberrypi.org jessie InRelease
Get:2 http://repo.mosquitto.org jessie/main armhf Packages [2211 B]
This tutorial is tested on:
Raspbian jessie 8.0 Lite
Linux raspberrypi 4.9.35-v7+
Now if you are using Raspbian Wheezy you should use following on step3:
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
For Stretch use following commands:
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-stretch.list
sudo apt-get update
wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u6_armhf.deb
sudo dpkg -i libssl1.0.0_1.0.1t-1+deb8u6_armhf.deb
wget http://ftp.nz.debian.org/debian/pool/main/libw/libwebsockets/libwebsockets3_1.2.2-1_armhf.deb
sudo dpkg -i libwebsockets3_1.2.2-1_armhf.deb
sudo apt-get install mosquitto mosquitto-clients
After researching this issue for a couple of days this is what I found to work for me and now my MQTT server is working great with the other devices in my house.
wget http://ftp.us.debian.org/debian/pool/main/libw/libwebsockets/libwebsockets3_1.2.2-1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl1.0.0_1.0.2l-1~bpo8+1_armhf.deb
sudo dpkg -i libwebsockets3_1.2.2-1_armhf.deb
sudo dpkg -i libssl1.0.0_1.0.2l-1~bpo8+1_armhf.deb
# If dpkg reported any packages missing, I used apt-get to get them from stretch repo
sudo apt-get install mosquitto
Raspbian Jessie
mosquitto 1.6.8
wget http://ftp.us.debian.org/debian/pool/main/libw/libwebsockets/libwebsockets3_1.2.2-1_armhf.deb
sudo apt-get install mosquitto
worked