Enabling Mosquitto websockets on Synology NAS

Websockets are cool. They are the modern sibling of http in that they run over tcp, but "EthernetCableBlue2" by Raysonho @ Open Grid Scheduler / Grid Engine - Own work. Licensed under CC0 via Wikimedia Commons - https://commons.wikimedia.org/wiki/File:EthernetCableBlue2.jpg#/media/File:EthernetCableBlue2.pngwebsockets offer a lot more, most notably full duplex (i.e. data can be sent in both directions) and realtime delivery of messages.

Those two features enable the creation of web pages that update dynamically as soon as new data is available on the server. No need to reload the web page in the user’s browser.

I have been struggling with how to get websockets integrated with MQTT on my Synology DS1515+ NAS, but in the end it turned out to be pretty easy!

MQTT is another very cool concept/protocol. Loosely related to IBM’s Messaging Queue (MQ) protocol, MQTT focuses on messaging between small footprint devices (low processing power, IoT etc). While it can in some cases be used to keep information about system state, it is in the machine-to-machine communication area the protocol really shines.

Mosquitto is one of the leading open source MQTT implementations. It runs on most platforms, from small devices like Raspberry Pi, as well as Windows, OS X and most major (a few more niche) Linux distributions. I have been using it on and off for a year or two, with a lot more done through MQTT/Mosquitto during the past 6 months. It has in many ways become the nervous system in the home automation and monitoring system at home here – everything from weather forecasts, frost alerts, temperature and energy usage monitoring, status of computers and network devices, arrival/departures of people etc etc – all kinds of data lives in MQTT in a structured, easy to get to, way.

And here comes the good part: As of version 1.4 of Mosquitto, web sockets are natively supported.

This opens up to some pretty cool possibilities. For example, it is now possible to create live web pages that always show the latest temperature/energy/forecast/presence/… information – all retrieved from a single source (rather than all sorts of different databases, REST APIs, external web services etc). Very powerful indeed!

Thanks to the great work by the SynoCommunity project, Mosquitto is available for many Synology NAS models, current version as of this writing is 1.4.2-4. Websockets are however not enabled by default, it is however very easy to do:

  1. Enable downloads from the SynoCommunity repository, as described on their site.
  2. Install Mosquitto, verify it is running. It will by default listen on port 1883, you can use a tool like MQTTLens (available on Chrome app store) or similar tools to verify that your newly
    installed MQTT broker is working. Just connect the MQTT client to your Synology’s IP address on port 1883, and you should be able to send and receive MQTT messages.
  3. ssh into your NAS as root, or as a regular user and then switch to root. Enabling SSH on Synology NASYou will need to enable ssh in the NAS control panel to do this. You should consider using a non-standard port (i.e. not 22), as it will at least somewhat decrease the number of attacks you will see on the port (if your NAS is open to the Internet). You should of course also have strong passwords, public key pairs to log in etc etc…
  4. Let’s find out where the Mosquitto config file lives:
    DS1515P> find / -name mosquitto.conf
  5. Edit the “Extra listeners” section of the Mosquitto config file. The VI editor is installed by default in the BusyBox shell (no VIM, Nano or similar – sorry..) so it reads something like this:
    # =================================================================
    # Extra listeners
    # =================================================================
    # Listen on a port/ip address combination. By using this variable
    # multiple times, mosquitto can listen on more than one port. If
    # this variable is used and neither bind_address nor port given,
    # then the default listener will not be started.
    # The port number to listen on must be given. Optionally, an ip
    # address or host name may be supplied as a second argument. In
    # this case, mosquitto will attempt to bind the listener to that
    # address and so restrict access to the associated network and
    # interface. By default, mosquitto will listen on all interfaces.
    # listener port-number [ip address/host name]
    listener 9001
    # The maximum number of client connections to allow. This is
    # a per listener setting.
    # Default is -1, which means unlimited connections.
    # Note that other process limits mean that unlimited connections
    # are not really possible. Typically the default maximum number of
    # connections possible is around 1024.
    #max_connections -1
    # The listener can be restricted to operating within a topic hierarchy using
    # the mount_point option. This is achieved be prefixing the mount_point string
    # to all topics for any clients connected to this listener. This prefixing only
    # happens internally to the broker; the client will not see the prefix.
    protocol websockets
  6. Sample Mosquitto config files are found in the /usr/local/mosquitto/etc/mosquitto/ directory, they are very useful if you want to add additional features like security to your Mosquitto setup.
  7. Restart Mosquitto from the package center app in the Synology web UI, and you are good to go. You now have a websockets enabled MQTT server.


More to come on this topic, I suspect.. got some neat ideas brewing.


If you want to read up on MQTT and Mosquitto, I recommend Jan-Piet Mens’ blog, lots of great posts about MQTT, advanced DNS usage and other goodness.



17 Replies to “Enabling Mosquitto websockets on Synology NAS”

  1. Why the line “listener 9001”?
    It works for me with the default port 1883.

    At first, I logged in as “admin”, then found the file, but vi does not allow me to save this read only file.
    Solution: log in as root with the admin password…

    1. Good questions.
      The listener on port 9001 was needed as I had other, non websockets MQTT connections on port 1883.
      So I needed a new port for the websockets connections, I think someone mentioned somewhere that 9001 was the one to use… Any free port should work though, I suspect.

      And yes, you prob need to be root to do this – don’t quite remember – but that does seem reasonable.

  2. Thanks for the info! When I try to add “protocol websockets” to my mosquitto.conf file, my mosquitto service refuses to start. Any ideas on what could be wrong? (I’m on mosquitto 1.4.2-3, no newer version is shown in my package manager)

    1. A synology update allowed the mosquitto package to update, which solved the problem!

  3. Well I added the extra lines to conf and now websockets on 9001 work but non-websockets mqtt port on 1883 doesn’t anymore?! Can’t both run?

  4. Thanks for this post … i was looking for a mqtt broker/server for my virtual machine
    but the idea to have it on my synology is even better.
    but …. it does not run on my ds1512+
    i can edit the mosquito.conf as root.
    but the mosquito package will not run (on my dsm 6 update 4 ) .. nor comes there a entry in the log

  5. I am reasonably sure


    is not the actual config file, more like the example in the package. Have a look at


    It point cleary to


    I don’t think they are symbolically linked.

    1. Well, given the install on my NAS, the config actually is at the location I mentioned in the blog post.
      But I can clearly see the config file end up elsewhere, if mosquitto is installed in a different way. So both might be right 🙂

    2. I don’t know how, but they are linked. changes in the one location happen in the other too.

  6. It wont install…”damaged install package”. I’ve got a DS214+…is that compatible?

    1. Hmm, not sure.
      Since writing the original post I have moved over to running everything in Docker containers.
      I.e. run Synology’s official Docker package, and then run Mosquitto, Node-RED, databases etc on top of Docker.
      Makes it waaaay easier to install, update and manage the tool stack you need.
      Some Docker skills needed of course, but nothing really hard core.

  7. I was able to set up everything in DS218+

    1. Enable Admin login for Synology
    2. Enable SSH in NAS
    3. Download putty and connect to NAS Server
    4. Login using admin
    5. change to root user [sudo -i, {use admin password}]
    6. find mosquitto.conf file [find / -name mosquitto.conf]
    7. go to that path using cd [in my case cd /volume1/@appstore/mosquitto/var]
    8. edit mosquitto.conf [vi mosquitto.conf]
    9. Might say it’s used by another process. Force edit.
    10. Scroll down and find # allow_anonymous [around line 513]
    11. Remove # and make [allow_anonymous false] [Use insert on keyboard to edit]
    12. Scroll and find #password_file [around line 555]
    13. Remove # and make password_file /volume1/@appstore/mosquitto/var/password_file [where 2nd password_file is the actual filename]
    14. Save the file [Esc-> :wq to save]
    15. Now create a file password_file in /volume1/@appstore/mosquitto/var/
    16. ensure your are still in same directory, type vi password_file
    17. This will create new file, press insert and type your username and password in below format
    18. username:password [Username should not contain :]. You can add multiple users line by line
    19. save file and clseo [Esc->:wq]
    20. Find mosquitto_passwd [find / -name mosquitto_passwd]
    21. Stay in the mosquitto.conf folder itself. Because we have password_file file here.
    22. From mosquitto.conf folder, type mosquitto_passwd [along with path] -U password_file to encrypt password.
    23. In my case /volume1/@appstore/mosquitto/bin/mosquitto_passwd -U password_file
    24. Start/restart Mosquitto Server
    25. All done. Thank You.

Leave a Reply

Your email address will not be published.