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’ve successfully was able to 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?
- 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 have the websockets server listening/answering.
After the change, stop and start the Mosquitto broker on the package manager action dropdown box for the Mosquitto package.
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 0.0.0.0:9001 0.0.0.0:* LISTEN tcp 0 0 192.168.1.250:9001 192.168.1.32:55331 ESTABLISHED
In the above case we can see that there is a websocket client connected to the broker from my workstation.
For testing we can use the HiveMQ websocket client: http://www.hivemq.com/demos/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: 192.168.1.250, 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!