Mosquitto Broker with Websockets enabled on the Synology NAS

Synology NAS are great devices, mainly due to the bundled software (CloudStation, Photo Station, to name a few), but also because it can run other software that is provided on non official package sources.
One of such providers is the SynoCommunity that provides a Mosquitto MQTT broker packaged for the Synology NAS. While I was able to successfully cross compile the Mosquitto broker for my DS212+ NAS with websockets enabled (I do have a draft post with the steps that I’ve never published), the SynoCommunity package allows a simpler way to install and use a Mosquitto broker that has the WebSockets protocol support compiled in.

So, what is needed to be done?

Setting up:

  • 1st: Add to your Synology server the SynoCommunity package source. See the detailed instructions on the community web page.
  • 2nd: Install the Mosquitto package from the Synology package manager.
  • 3rd: Edit the file located at /usr/local/mosquitto/var/mosquitto.conf. You need to connect through ssh as root to do this.

At the end of this file add the following lines:

listener 1883
listener 9001
protocol websockets

Note that the 1883 is the standard MQTT broker port, and 9001 is the port that I’ve choose to have the websockets server listening/answering.

After the change, we need to stop and start the Mosquitto broker on the package manager action dropdown box for the Mosquitto package, so that the change can be assumed.

Still using ssh, and logged in as root, check now that the port 9001 is active:

root@DiskStation:/volume1/homes/root# netstat -na | grep 9001 
tcp        0      0  *               LISTEN       
tcp        0      0      ESTABLISHED

In the above case we can also see that there is a websocket client connected to the broker from my workstation (the second output line).


For testing we can use the HiveMQ websocket client: that allows to communicate using the websockets transport.

Despite the fact that the page is available on an external, internet based server, the websocket client will be running on YOUR web browser, on your machine in your own (internal) network, so at the connection settings for the broker, for Host I use my internal IP address:, and for the Port: I use the 9001 value.

I can now subscribe and publish to topics using the browser, and also using MQTT-SPY we can see and check the MQTT Websockets communication.

And that’s it!

20 thoughts on “Mosquitto Broker with Websockets enabled on the Synology NAS

  1. Thanks for this tutorial.

    On my synology, for the line to add to mosquito.conf, i have to key :

    listener 9001
    protocol websockets

    1) instead of listen
    2) without upercase for protocol

      1. I stand corrected. You are right, it is Listener and not Listen.
        I’ve corrected the post.

  2. Too bad, It doesn’t look the port is opened

    NAS> netstat -na | grep 9001
    tcp 0 0* LISTEN

    Running Mosquitto 1.4.2-4
    Synology: DSM: 5.2-5644 Update 1

      1. ok, so tcp 0 0* LISTEN <- means it is open by the listener. (my poor linux knowledge)

  3. 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)

  4. Thanks for the write up. Works a treat. Do you know how to add a username and password to the Mosquitto instance as I get ‘-ash: mosquitto_passwd: not found’ when I run the standard Mosquitto command?

    1. Hi, the mosquitto_passwd is not in the path, hence the shell fails to find it.

      Have a look at the following:

      root@DiskStation:/volume1/@appstore/mosquitto/bin# pwd
      root@DiskStation:/volume1/@appstore/mosquitto/bin# ./mosquitto_p
      mosquitto_passwd mosquitto_pub
      root@DiskStation:/volume1/@appstore/mosquitto/bin# ./mosquitto_passwd
      mosquitto_passwd is a tool for managing password files for mosquitto.

      Usage: mosquitto_passwd [-c | -D] passwordfile username
      mosquitto_passwd -b passwordfile username password
      mosquitto_passwd -U passwordfile
      -b : run in batch mode to allow passing passwords on the command line.
      -c : create a new password file. This will overwrite existing files.
      -D : delete the username rather than adding/updating its password.
      -U : update a plain text password file to use hashed passwords.

      See for more information.


  5. websockets now work, but now normal mqtt port/protocol doesn’t work anymore?! Can’t both protocols be run (on different ports)?

    1. Make sure there are no blank lines between the Listener and the protocol directives. Both work at the same time.

  6. Just to be more specific the mosquito failed to run.
    I can edit the mosquito.conf file as root. but still it fails to run at my ds1512+

    1. Did you check the mosquitto log file for any errors? It might be something else not related to the DSM update…

  7. For testing we can use the HiveMQ websocket client: well … it works but .. also with my NAS turned off ????
    So what you really testing with this mqqt client

    1. As far as I’m aware, no protocol works with a shutdown server. Maybe your HiveMQ client for server connection is misconfigured?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.