How to install the MQTT Mosquitto server

Eclipse Mosquittoâ„¢ is an open source 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.

Installing the default Debian Mosquitto package

The default package available from the Debian repository is enable just for the MQTT protocol. These are the commands to install it.

sudo apt update
sudo apt install mosquitto

Installing Mosquitto with support for websockets

If you need to manage also the Websockets protocol (requested by Javascript program inside a web pages to publish/subscribe events) you have to create a new file called /etc/mosquitto/conf.d/websocket.conf with this content:

listener 1883
listener 1884
protocol websockets

Then restart Mosquitto:

service mosquitto restart

Test if Mosquitto is working

To test if Mosquitto is working on your board make a subscription to the broker to receive all messages:

mosquitto_sub -h localhost -t "#" -v

Then open another therminal session and send a messagge to the topic "test":

mosquitto_pub -h localhost -t "test" -m "Hello world!"

You will see the message received.

Links

  • http://blog.ithasu.org/2016/05/enabling-and-using-websockets-on-mosquitto/
  • http://blog.ithasu.org/2016/05/setting-up-mosquitto-on-raspbian-jessie/
  • https://mosquitto.org/man/mosquitto-conf-5.html

Sergio Tanzilli
Systems designer, webmaster of www.acmesystems.it and founder of Acme Systems srl

Personal email: tanzilli@acmesystems.it
Web pages: https://www.acmesystems.it --- https://www.acmestudio.it
Github repositories: https://github.com/tanzilli --- https://github.com/acmesystems
Telegram group dedicated to the Acme Systems boards: https://t.me/acmesystemssrl