Cannot connect to mosquitto MQTT Broker

Hello,

I have been learning node red for the past days and I wanted to start working with MQTT. For this I installed Mosquito on my Mac and created an MQTT broker. I know it works since I can play with it in the terminal using mosquitto_pub and mosquitto_sub, but when I try to connect to the broker using bordered it cannot connect.
I use the localhost:1883 (I checked and this is the port where my broker is)

Can anyone help me please? anything can help, I have read that I need to edit the conf file from mosquitto but I don't know how to do that either.

Thank you in advance

In the mqtt nodes, you need to define the location of the broker. If you install the broker on device A (let's say it's IP address is 192.168.1.50) and NR is installed on device B (let's say it's IP address is 192.168.1.75), in the MQTT configuration you need to enter 192.168.1.50 as the server address

If your network knows about the device names you can use the device name in the server entry like mqttpizw.local (this is a pi zero w that I'm running mosquitto on)

I have both (node red and mosquitto) running on the same device, if this is the case I should be able to connect using localhost right?

I’m not sure since I’ve never done it. You can take a dive into the mosquito configuration documentation if you want.

Check out the ‘bind_address’ option.

As @zenofmud said you need some configuration for the mosquitto broker to accept connections

I found a post on the forum about it where, since mosquitto version 2, some security settings need to be added :

allow_anonymous true
listener 1883

restart the brocker and also check if anything else (firewall?) is blocking the connection

So are you saying you have installed NodeRed natively on the Mac also ? And Mosquitto also - not in Docker containers ?

Craig

1 Like

Hi,
I am running both in docker containers

You can't use localhost from a docker container. You must use the ip of the mosquito container.

I got the IP for the container and it still didn't work... also, if I try to connect with Mqtt explorer, I use localhost and it works just fine, I don't understand :frowning:

The two docker containers have their own IP address. To connect from one docker container to another docker container, you need to use the IP address of the second container. Also, as mosquito V2 is more secure by default, you need to edit the conf file to permit external connections other than localhost.

1 Like

This would have been good to have told people at the start

We need to see the startup commands for the two containers to see which ports have been mapped to external ports on the host.

It would be a good idea to install Portainer (you can run that as a container as well) as this will give you much more visibility as to what the containers are doing and let you access their runtime parameters etc

Craig

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.