2
votes

I'm trying to connect to a local mosquitto mqqt broker via websockets and the paho javascript client. However, using the example shown at https://www.eclipse.org/paho/clients/js/ crashes my network connection. In the chrome or ie console I found the problem: The connection is made over and over again (function onConnect is called multiple times per second).

client.connect({onSuccess:onConnect});  
// called when the client connects
function onConnect() {
  // Once a connection has been made, make a subscription and send a message.
  console.log("Connection was successful");
  client.subscribe("World");
  message = new Paho.MQTT.Message("Hello");
  message.destinationName = "World";
  client.send(message);
}

On the broker I can see the client connecting:

New client connected from 192.168.1.3 as web_78 (c1, k60, u'user123').

But the message does not get broadcasted by the client. When I terminate the browser, I see on the client:

Socket error on client web_78, disconnecting.

The same thing happens, when I try different Codeexample like this one: https://jpmens.net/2014/07/03/the-mosquitto-mqtt-broker-gets-websockets-support/

I'm using mosquitto version 1.5 on my Raspberry Pi and have really no Idea, how I can get this running. Maybe the problem is the mosquitto server and not the client?

This is the part of my mosquitto.conf where I define the ports

listener 9001
protocol websockets

Other clients can connect (e.g via paho python) and mqtt (without websockets).

pi@raspberrypi ~ $ sudo mosquitto -c /etc/mosquitto/mosquitto.conf
1530009485: mosquitto version 1.5 starting
1530009485: Config loaded from /etc/mosquitto/mosquitto.conf.
1530009485: Opening websockets listen socket on port 9001.
1530009485: Opening ipv4 listen socket on port 1883.
1530009485: Opening ipv6 listen socket on port 1883.
1530009485: New connection from 192.168.1.51 on port 1883.
1530009485: New client connected from 192.168.1.51 as DVES_9CE05F (c1, k15, u'johann').

Any help would be highly appreaciated!

EDIT Update:

The problem must be within my server, as I can access public broker like HiveMQ.

1
Are you using the paho example unchanged (apart from the address of the broker)?hardillb
yes, just changed the ip address and the port.JohnnyD.
I've just built the v1.5 source on x86_64 Ubuntu and it's behaving properly. Where did you get your raspberry pi build?hardillb
Also it looks like you edited the example to change the client id and set a username and password, please update the question with that code change.hardillb

1 Answers

0
votes

I had the same problem. There is a problem related to libwebsockets in Mosquitto 1.5.x, at least in the version that are installed on Raspberry Pi with Raspbian jessie. When I downgraded Mosquitto to 1.4.15 this problem was solved for me.

Read about it in, https://github.com/eclipse/mosquitto/issues/1050