I am working with MQTT communication for an IOT project. I installed a Mosquitto broker in Windows and everything works ok when I work among subscribers and publishers in Python or via command line between machines of the same local network. For the web client I am using mqttws31.js and to test it I used a mosquitto broker mounted on an external Linux server that works perfectly. It also works when the client host is configured with Localhost. However when I configure it with the Ip of the same localhost server, it stops working. I leave the background:
- Server: mosquitto-1.5.3 (accepts ws) link
- JS Client: link
- mosquitto.conf Contains the correct configuration:
- listener 1883
- listener 1884
- protocol mqtt
- istener 2883
- websockets protocol
Start with: mosquitto -c mosquitto.conf
client js
mqtt = new Paho.MQTT.Client(localhost,2883,"clientjs"); // Funciona, pero
//obviamente no sirve porque al consumirlo, el cliente de otra máquina local
//dirigirá a su propio localhost.
mqtt = new Paho.MQTT.Client(192.168.1.36,2883,"clientjs"); // No funciona.
//La ip 192.168.1.36 es la ip de la máquina servidor
//(es decir es la ip del localhost) que contiene el broker
Error : WebSocket connection to 'ws: //192.168.1.36: 2883 / mqtt' failed: Error in connection establishment: net :: ERR_CONNECTION_REFUSED
Actions taken
- The mosquitto server is enabled in the Windows firewall
- Port 2883 is enabled in the windows and router firewall (although not if it is well configured)
Conjectures
- If the JS client works well using an external broker, the problem is not with the client, but with the server.
- If the client js works well using the local broker "Localhost" it is because "it is well configured".
- If the client js does not work in the same local broker "Localhost" using the ip ... I have no idea why it can be ...
Note: I know that everything would work better in Linux but in this case we should use a Windows server for the broker.