Client Side
When I try to connect my angular application running ngx-mqtt to a mqtt broker with a public facing IP address I end up getting these errors on my browser (Firefox) console log:
This is how the connection details are setup on my angular app using ngx-mqtt:
export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions =
{
hostname: '<BROKER IP ADDRESS>',
username: '<BROKER USERNAME>',
password: '<BROKER PASSWORD>',
port: 9001,
// protocol: 'ws',
// path: '/mqtt'
};
They match the details I created on the mqtt broker pc.
Broker/Server Side
On the mqtt broker I'm using mosquitto
I've configured the mosquitto.conf file ensuring websockets is enabled and the correct port 9001 is open as an extra listener alongside the default mqtt listener with port 1883.
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
#include_dir /etc/mosquitto/conf.d
allow_anonymous false
password_file /etc/mosquitto/pwfile
listener 1883
listener 9001
protocol websockets
After saving the mosquitto.conf file and restarting mosquitto, I run the mosquitto command and get the following output, it only says the default 1883 port is open:
According to this blog running the command mosquitto -c /etc/mosquitto/mosquitto.conf should give me outout that tells me port 9001 is open and listening, and is loaded from the mosquitto.conf file.
But I get no output when I run that command.
I even tried making sure the firewall and port fowarding was enabled for port 9001.
I've also tried doing some of the things suggested in this question. But no matter what I try I can't get websockets to work on this public facing IP mqtt broker.
The strange thing is if I try to do this via a local network mqtt broker it works fine, it's only when I try to connect to a public IP mqtt broker that I get these issues.
If it helps the LAN mqtt broker that works is a raspberry pi 3 running raspberry pi os whereas the public IP WAN mqt broker is running ubuntu on an intel nuc.
If anybody could help it would be appreicated.
Okay so it turns out there was nothing wrong with my configuration. The issue was Firefox for some reason, I tried running my angular app with Chromium and it connected to the MQTT broker right away.