Hello David M
Welcome to Microsoft Q&A Platform, thanks for posting your query here.
Based on the details shared, looks likeIt seems that you are trying to connect to the MQTT broker running on your Azure VM from an external device. However, you mentioned that you have already allowed the MQTT ports (1883 and 8883) in the Azure firewall.
One possible reason for the "Connection refused" error is that the MQTT broker is not listening on the public IP address of your VM. By default, the Mosquitto broker listens on the loopback interface (127.0.0.1) only, which means that it can only accept connections from the same machine.
To allow external connections to the Mosquitto broker, you need to modify its configuration file (/etc/mosquitto/mosquitto.conf) and add the following lines:
listener 1883
listener 8883
This will make the broker listen on all network interfaces, including the public IP address of your VM.
After modifying the configuration file, you need to restart the Mosquitto service for the changes to take effect:
sudo systemctl restart mosquitto
Once the service is restarted, you should be able to connect to the broker from an external device using the public IP address of your VM.
Hope this helps.