Tutorial: Install Mosquitto MQTT on Synology NAS

If you have followed our virtual machine creation tutorial Home Assistant on NAS Synology, you probably already want to go further. That's good, so are we. We will therefore see today how install a Mosquitto MQTT broker on a Synology NAS.

There are several solutions and other MQTT brokers, but at Les Alexiens we like simplicity and efficiency, and we are not going to get into installing a virtual machine or using Docker, because There is a very simple solution: a Mosquitto MQTT package all ready available on the Synology community.

Mosquitto MQTT: a broker on your NAS Synology

Prerequisites

Obviously, you need a NAS from the Taiwanese company. The good news is that this time no need to have a racing beast, this is just a simple little package that won't ask neither container nor virtual machine and which runs on the DSM operating system. A solution that will therefore be of interest to all owners of Synology DiskStation !

If you don't have a NAS, you can install an MQTT broker on Raspberry Pi:

TO READ :
Tutorial: Mosquitto MQTT on Raspberry Pi

If you still don't know which home automation NAS to choose, we recommend that you read our file and in particular these models:

TO READ :
Which NAS to choose for your home automation?

What is an MQTT broker?

Well, that's all well and good, but what is MQTT? It's very simple, it's a publish/subscribe protocol allowing edge of network devices to publish to a « broker« .

What ? Isn't that clear? It's true. Let's simplify.

Actually, it's not that complicated, it just means that your broker will publish topics to which customers will be able to subscribe. Each customer can subscribe to different topics and publish messages there that the MQTT broker will relay to all clients subscribed to topics. This is called a bidirectional protocol.

Concretely, if our client is a connected thermometer, it will transmit the temperature it records in the house to its MQTT broker on a topic called /temperature to which various subscribers MQTT customers such as a boiler or an application (Jeedom, Home Assistant, Homey, etc.). The application and/or the boiler can then use this information to activate a home automation scenario. Your heater will be able to turn on or off, even if it does not use the same protocol as the thermometer. Even better, when it lights up, it will notify the broker who, in turn, will notify other clients. The circle is complete !

To popularize, a MQTT broker is therefore a kind of super home automation hub with which you will be able to coordinate several protocols: Z-Wave, ZigBee, Wi-Fi, Bluetooth, and much more… The main advantage of this protocol lies in its extreme lightness. Thus it is 90 times faster than HTTP protocol and also much less energy-consuming since it requires 10 times less energy to send messages and 170 times less to receive. It is therefore ideal for small connected objects such as battery-operated sensors, wireless switches, etc.

Install Mosquitto MQTT on Synology

Certainly, Mosquitto is not the only broker, but it is the most widely used and the community of NAS Synology users has released a great package that we would be wrong not to use.

Indeed, its process occupies on average only 1.8MB RAM ! Suffice to say that it is not he who will make your NAS smoke… No need, therefore, to weigh down our machine with yet another VM or to use a Docker container (unless you use Docker for other things obviously).

Let's move on to the actual installation:

    1. Add source : for this, you must add Synocommunity as a source if you are not already using it.
      Package Center > Community > Package Sources > Add
    2. Fill in the address on the package :
      https://packages.synocommunity.com
    3. Install the package : Mosquito MQTT
      Package Center > Community > Mosquitto MQTT
    4. Stop Mosquitto MQTT : if the packet is launched, stop it.
    5. Login in SSH : Enable SSH service on your NAS and use a console such as Windows PowerShell (Windows 10 or 11), PuTTY, or Terminal on macOS.
      ssh [email protected] -p 22 (NAS IP address and port)
    6. Become root :
      sudo -i: enter your admin password
    7. Find the location of the configuration file :
      find / -name mosquitto.conf
    8. Open the folder /mosquitto/var folder in @appstore :
      cd /volume1/@appstore/mosquitto/var
    9. Edit the Mosquitto configuration file with an editor such as vim by pressing "i" :
      vim mosquitto.conf
      
    10. Find the lines, delete the # and replace with:
      Line 650: allow_anonymous false Line 668: password_file /volume1/@appstore/mosquitto/var/fichier_mot_de_passe (replace with the name of your choice)
    11. Exit vim and save with the command:
      :q or :quit
    12. Now create the password file entered previously:
      vim password_file (the name chosen above)
    13. Enter the following command to add a user (replace the terms of course):
      user:password
    14. Locate the mosquitto_passwd file:
      find / -name mosquitto_passwd
    15. For security, it is better to encrypt the mosquitto_passwd file by entering its address marked above. You should have something like:
      ../bin/mosquitto_passwd -U password_file
    16. It's over : you can go back to DSM and run the Mosquitto MQTT package again

      ../bin/mosquitto_passwd -U password_file
Mission accomplished ! Congratulations, you now have a MQTT broker on your Synology NAS. Let's see what it looks like with the GUI of an MQTT client…

Use an MQTT client

Finally, we will see if our broker works well using a free MQTT client which will allow us to read the topics, but also to publish them, and possibly to intervene on certain parameters if necessary. Our preference is MQTT Explorer, but there are others. Available for PC and Mac, this program will be very useful to us in our next tutorials.

  1. Install the client MQTT Explorer
  2. Fill in the address IP of your NAS in "Host",
  3. Let him port 1883
  4. Enter your identifiers in 'Username' and 'Password' (those chosen for Mosquitto, not those of your NAS).

In a few seconds, you discover the interface of MQTT. Well, for now, she doesn't have much empty interest, but here's what she will look like after our next home automation tutorials DIY.

For Homey Pro owners, you can very quickly link your broker to your home automation boxes by following our dedicated tutorial:

TO READ :
Tutorial: setting up MQTT on Homey Pro

For the others, we will soon see how to link this Mosquitto MQTT broker to Home Assistant, then how install Zigbee2MQTT, and much more… Stay connected!

Fascinated by Alexa since the day I received it in beta test, I gradually became passionate about the subject, before deciding to go further by creating a site with Jean-Christophe. An activity that allows me to quench my thirst for new technologies and share my discoveries about the nicest of communities: Les Alexiens.