javascript - How to connect to a Mosquitto broker on a Raspberry Pi through web sockets? -
i trying connect raspberry pi has mosquitto broker installed. client on rpi connected using:
client.connect("127.0.0.1", 1883, 60)
i tried connect on mqtt javascript client using following specifications failed:
client = new paho.mqtt.client("10.101.125.190", 1883,"myclientid_" + parseint(math.random() * 100, 10));
i tried changing port 8080
javascript side still failed. if change port 8080
on rpi won't connect.
this error getting @ moment:
websocket connection 'ws://10.101.125.190:1883/mqtt' failed: error during websocket handshake: net::err_connection_reset
so, need change fix error? rpi , js client both in same local network.
edit: forgot mention have tried test.mosquitto.org - 8080
, worked, change address start getting error.
mqtt on websockets not share same port native mqtt.
you need add new listener mosquitto config.
you need add following end of /etc/mosquitto/mosquitto.conf (or in seperate file in /etc/mosquitto/mosquitto.d)
listener 1884 protocol websockets
then need update javascript connect port 1884 not 1883
you need using version of mosquitto newer than 1.4.x iirc default version packaged raspbian old. follow instructions here newer version.
Comments
Post a Comment