1
votes

I am running the MQTT mosquitto broker (v.1.4.15) on a Azure Virtual Machine running Ubuntu (v18.04.1). My aim is to connect multiple microcontrollers to the broker. In order to monitor and control the microcontrollers remotely, I've setup an Azure WebApp on which I am running Node-RED. I am trying to establish a connection between the web-app and the broker. In order to configure Mosquitto properly, I am using this tutorial from DigitalOcean. However, because I'm new to this part of the work (usually working on embeded systems) I'm trying to establish a connection without SSL first for testing and then add SSL.

I've password protected mosquitto and am able to pub and sub on a test topic on local host (using the following commands on the VM terminal)

$ mosquitto_pub -h localhost -t "test" -m "message" -u "user" -P "password"
$ mosquitto_sub -h localhost -t "test" -u "user" -P "password"

I've also configured mosquitto to listen to the port 8883 on the VM: /etc/mosquitto/conf.d/default.conf

allow_anonymous false
password_file /etc/mosquitto/passwd

listener 1883 localhost

listener 8883

Lastly, I've updated the firwall on the VM to allow connections to port 8883.

$ sudo ufw allow 8883

However, when I try connecting an MQTT node on the WebApp on Node-RED to the broker, the status remains "connecting". Is there a way to test this other than on the WebApp (maybe through the cmd prompt) or am I missing somehting?

Furthermore, when restarting mosquitto (after the edit to the config file and to the ufw) and running mosquitto:

$ sudo systemctl restart mosquitto
$ mosquitto

I get the following message from the terminal indicating that mosquitto is only listening to port 1883.

1610290040: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300) starting
1610290040: Using default config.
1610290040: Opening ipv4 listen socket on port 1883.
1610290040: Error: Address already in use
1
I'm not familiar with Azure VMs but most cloud providers include their own firewall that you need to open ports in as well as ufw on the machine it's self.hardillb
Fair enough, I'm not super familiar with them either and will look more into that but I also have the problem that mosquitto doesn't seem to be listening to port 8883 (I've appended more info about that to the post)Quentin_P
You are trying to run 2 copies of mosquitto (You restarted the system daemon version with new config using the systemctl command and then try to start another with mosquitto, with no the defaults) at once, that won't work.hardillb
I'm not sure what you're saying. I'm not trying to run 2 instances of mosquitto but I was trying to check what ports it was listening to (and 8883 doesn't appear).Quentin_P
The error message is explicitly because you tried to start a second instance, it can't start because the daemon version has already bound to port 1883 (and port 8883). The second instance (which you haven't passed a config file) won't show port 8883 because it not been told to listen on that port. Just running mosquitto will not read the config file in /etc/mosquitto.hardillb

1 Answers

0
votes

To follow up on the first comment.

You need to open the port in the Azure portal as well as in ufw

Details of how can be found here:

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nsg-quickstart-portal