Since version 1.4, mosquitto MQTT broker starts to support websockets natively. Now it is a try out for this great new feature.
The websocket support is not enabled by default, so we have to fetch the source code firstly and update one line in file config.mk
change it to yes , then you can compile and install it.
In case you got dependency errors, install the package as below.
apt-get install libc-ares-dev libwebsockets-dev libssl-dev uuid-dev
Try to start mosquitto broker with command mosquitto to see if it is working properly.
Then we need a customized mosquitto config file, let’s call it mqtt.conf
Now when we start with the command mosquitto -c mqtt.conf , you should see something like this:
An example code would look like:
Initially it looks like
If we start to send some messages from command like, we will get the data coming via mqtt through mosquitto broker and then via websocket published to js client.