Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Mosquitto MQTT on Synology NAS Server
From https://synocommunity.com add http://packages.synocommunity.com to your NAS package sources.
For that, go to NAS->Package Cnter->Click Settings->Package Sources tab.
Then from the community, you can see Mosquitto. Install it.
After installing, please stop the Mosquitto service before updating configuration. You can start service after changes.
Enable Admin login for Synology
Enable SSH in NAS
Download putty and connect to NAS Server
Login using admin
Change to root user [sudo -i, {use admin password}]
Find mosquitto.conf file [find / -name mosquitto.conf]
Go to that path using cd [in my case cd /volume1/@appstore/mosquitto/var]
Edit mosquitto.conf [vi mosquitto.conf]
Might say it's used by another process. Force edit.
Scroll down and find # allow_anonymous [around line 513]
Remove # and make [allow_anonymous false] [Use insert on keyboard to edit]
Scroll and find #password_file [around line 555]
Remove # and make password_file /volume1/@appstore/mosquitto/var/password_file [where 2nd password_file is the actual filename]
Save the file [Esc-> :wq to save]
Now create a file password_file in /volume1/@appstore/mosquitto/var/
Ensure your are still in same directory, type vi password_file
This will create new file, press insert and type your username and password in below format
username:password [Username should not contain :]. You can add multiple users line by line
Save file and clseo [Esc->:wq]
Find mosquitto_passwd [find / -name mosquitto_passwd]
Stay in the mosquitto.conf folder itself. Because we have password_file file here.
From mosquitto.conf folder, type mosquitto_passwd [along with path] -U password_file to encrypt password.
In my case /volume1/@appstore/mosquitto/bin/mosquitto_passwd -U password_file
Start/restart Mosquitto Server
All done. Thank You.
@intector
Copy link

intector commented Aug 3, 2019

Thank you,
very good description.

@ceraz68
Copy link

ceraz68 commented Aug 31, 2019

Hi do you know if this broker retains mqtt messages somewhere? The mosquitto base documentation points to a mosquitto.db file that would need to be deleted but this doesn't seem to exist on the synology package.
Thanks

@intector
Copy link

intector commented Aug 31, 2019

@k3it
Copy link

k3it commented Aug 31, 2019

Hi do you know if this broker retains mqtt messages somewhere?

if the retain flag is set mqtt keeps the last message received, if there are subscribers to topic. see here
http://www.steves-internet-guide.com/mqtt-retained-messages-example/

mosquito.db is used only if you enabled persistence to preserve in-memory db state after restart

@thuantclv
Copy link

thuantclv commented Oct 3, 2019

thank you so much!

@moccajava
Copy link

moccajava commented Oct 22, 2019

hello. i have installed the eclipse-mosquitto image from within synology docker. image runs ok with no errors and i see the port in the details says 1883. however, when I went over to my NAS IP:1883, it does not show up the MQTT page. Any help?

@absalom-muc
Copy link

absalom-muc commented Dec 28, 2019

Hi,
Thank you for the description!

In general mosquitto 1.4.14-9 is working on my DS218+, but I couldn't find a way to enable the logging. I added in mosquitto.conf:

log_type all
log_dest /volume1/public/mosquitto-log/running.log

I tried it with different locations for log_dest, but the result in moquitto.log is always

Starting mosquitto command /volume1/@appstore/mosquitto/sbin/mosquitto -d -c /volume1/@appstore/mosquitto/var/mosquitto.conf
Error: Invalid log_dest value (/volume1/public/mosquitto-log/running.log).
Error found at /volume1/@appstore/mosquitto/var/mosquitto.conf:465.
Error: Unable to open configuration file.

I assume mosquitto has no write permissions but I don't know how to solve it.
Do you have an idea?
Thank you.

@Rongab
Copy link

Rongab commented Feb 22, 2020

It worked perfectly :-) thank you for this very detailed & clear tutorial

@jjonkie
Copy link

jjonkie commented Mar 8, 2020

I'm a noob, never used putty before and managed to get to step 24... but now i'm stuck. I can't find the file and not sure what to do with te command on 26/27

@anthunter70
Copy link

anthunter70 commented Mar 12, 2020

thanks for the clear guide.
@jjonkie: line 27 is how the command looks like if your paths are the same as in the instruction.
so line 26 explains what kind of instruction, line 27 shows how to write out the instruction:
/volume1/@appstore/mosquitto/bin/mosquitto_passwd -U password_file

@DoganM95
Copy link

DoganM95 commented Apr 22, 2020

thanks for the guide!

@oddbytes
Copy link

oddbytes commented May 28, 2020

Thanks!

@fastlink30
Copy link

fastlink30 commented Jun 9, 2020

thanks

@ajumalp
Copy link
Author

ajumalp commented Jun 25, 2020

Hi all,

I'm very happy to know this was helpful to you all.

Thank You

I've published a code to Automate Home and Office here

Smart Home

Get the source code here

A web based complete source code for Home Automation including ESP8266 firmware.
This application helps to control electronic devices remotely. This can be installed in your local network, and because you all have Synology NAS Server you can access your devices from any where. You need a WiFi/Ethernet at Home/Office to connect Arduino devices. Then from your phone, you can control connected appliances

  • This support PWA [Progressive Web App]. So this can be easily installed into any OS supporting PWA
  • The Arduino code for the devices is also included in the Hardware folder
  • Mainly supporting ESP8266 devices
  • Mainly developed for Synology NAS Server [tested in DS218+]

@krzychb
Copy link

krzychb commented Sep 13, 2020

This instruction was very helpful for me, thanks @ajumalp!

@quizzical86
Copy link

quizzical86 commented Dec 7, 2020

Many thanks for these instructions. The find functionality didnt work for me but I didn't needit. More importantly I cound encrypt my password as I got errors that my password file was corrupt. The workaround I found was to let the mosquitto_paswd tool add the username and password (immediately encrypted) into the password file. This is the command:
/volume1/@appstore/mosquitto/bin/mosquitto_passwd -c password_file addyourusernamehere
It will then prompt you for the desired password twice

@ThierryM
Copy link

ThierryM commented Apr 7, 2021

Thanks for the sharing @ajumalp !
I updated (April 7th 2021) in french here : https://lofurol.fr/joomla/electronique/domotique/279-nas-syno-installation-du-broker-mosquitto-mqtt
Regards

@ebolisa
Copy link

ebolisa commented Sep 27, 2021

Hi, thanks for sharing.

I followed through and set it up with no errors.
However, when connecting with any client, it's connecting with any name/password. It's like if 'allow_anonymous false' has no effect.
Listing the files, I noticed a differance in users between the password file and conf. Could that be the problem?
TIA

$ ls -la
total 56
drwxr-xr-x 2 sc-mosquitto sc-mosquitto 4096 Sep 27 12:33 .
drwxr-xr-x 9 sc-mosquitto sc-mosquitto 4096 Aug 11 00:08 ..
-rw-r--r-- 1 sc-mosquitto sc-mosquitto 44637 Sep 27 01:48 mosquitto.conf
-rw-r--r-- 1 root root 116 Sep 27 12:33 pwd_file

EDIT:
I changed the owner/groupship for file pwd_file with no avail. Of course, did stop/run the server.

@dieterplex
Copy link

dieterplex commented Oct 8, 2021

I followed through and set it up with no errors. However, when connecting with any client, it's connecting with any name/password. It's like if 'allow_anonymous false' has no effect. Listing the files, I noticed a differance in users between the password file and conf. Could that be the problem? TIA

Face similar case on my DSM 7.0.1. Make sure you edit config file
from /volume1/@appdata/mosquitto/mosquitto.conf,
not_ /volume1/@appstore/mosquitto/var/mosquitto.conf.

@ebolisa
Copy link

ebolisa commented Oct 8, 2021

@dieterplex thank you.

@mager33
Copy link

mager33 commented Feb 20, 2022

to avoid multiple .conf files I just put one line in /volume1/@appdata/mosquitto/mosquitto.conf: "include_dir /volume1/@appstore/mosquitto/var/" and stayed with /volume1/@appstore/mosquitto/var/mosquitto.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment