Skip to content
Advertisement

Mosquitto and JavaScript Example not working (Firefox)

I would like to make a Websocket connection with TLS encryption to my mosquitto server. But I do not even get a simple example with the official mosquitto server running.

JavaScript

In the network Log I can see these statements:

JavaScript

Firefox (Mozilla Firefox for Linux Mint 89.0 (64-bit)) gives the error message Firefox can’t establish a connection to the server at wss://test.mosquitto.org:8081/mqtt.

Maybe somebody can give me a hint what’s wrong with my setup? Or a know working JavaScript example?

Thanks in advance, Christof

Advertisement

Answer

First increase the connection timeout, you currently have it set to 4 seconds, the default is 30 seconds. Because test.mosquitto.org is a totally public broker it often gets hammered by people (either testing stuff or just not thinking what they are doing) so a longer timeout is better.

Secondly, having a clientID of test_client is VERY likely to clash with another client so your client will get kicked off the broker as soon as the other client tries to reconnect which will cause your client to reconnect causing a connect/disconnect loop. ClientID’s need to unique across ALL clients connecting to the broker, I suggest you change this to a unique to you prefix combined with a random number.

Thirdly you don’t actually do anything even if you connect, you make no subscriptions, so the on message event handler will never be called. You don’t even have a on connect event handler to know if you ever get connected cleanly.

e.g.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement