My Raspberry Pis aren't connecting via Node Red with MQTT

I'm not understanding what I'm doing wrong. I have one Raspberry Pi as my broker. My other Raspberry Pi isn't receiving anything on its side.

What I did first was test the connection on the localhost on one Pi and that is working well.

But what I did was change both the MQTT In and MQTT out nodes to the IP address of my second Raspberry Pi that is connected away from my first one. I'm getting nothing. I also matched the Topic name on each, the broker is running on the second pi, and NodeRed is running on both, but I'm using the node only on the first Pi and not the second. What am I doing wrong?

  1. what MQTT broker are you running?
  2. what is the IP of the pi running the MQTT broker? (Let’s call this pi-a)
  3. what is the IP of the other pi? (Let’s call this pi-b)
  4. please export the mqtt-out node from node-red on the pi that works and paste it to a reply
  5. please export the mqtt-in node from node-red on the other pi and paste it to a reply
  6. what version of NR is running on each pi?

Did you set the broker configuration to allow remote connections ? They are blocked by default for security.


  1. What I did was follow this link: Install Mosquitto Broker Raspberry Pi | Random Nerd Tutorials I did it on both of my Pis. (I'll call one Pi-A and Pi-B)

  2. I used "hostname -I" to find the IP address of my Pi-A (142.#.#.#)

  3. I used the same thing on Pi-B and got a different IP address (142.#.##.#)

  4. I attached some pictures of what I used for MQTT-Out on Pi-A.

  5. I attached another picture of what I used for MQTT-In on Pi-B. I am running my MQTT broker on that Pi, and I'm thinking that may be wrong. But ultimately, on Pi-B, for topic I used "message" for the MQTT node and then I did the same for Pi-A on a different monitor with another node. I then used the IP address from Pi-B and assigned it to both MQTT nodes on the different monitors. I'm pressing send, and nothing is sending.

  6. I'm away from my lab, but I think because one Pi is a Pi3B+, I had to download a previous version of Node Red to make it work. I believe that I am running a newer version of Node Red on my Pi 4.

I made sure to change the config file to allow anonymous true, listener 1883 and I think another listener for the second Pi's IP address as well. I thought that might've been the cause of my problems, but the config file looked right to me.

You only need one mqtt broker. For example, let’s a]say you choos pi-a. In the mqtt configuration on pi-a specify the IP address of pi-a

On pi-b, in the mqtt node configuration also specify the IP address of pi-a.

I have the latest version of node-red (v3.0.2) running on RPI 3’s with no problem.

Just as an observation: 142.x.x.x is a public IP address. Are these on the open internet?

1 Like

Okay just to make sure. So after updating or retrying with the possible version problem, on Pi-A, I run the MQTT broker only on that. Then for each node on the different Raspberry Pi, I use the IP address of Pi-A that is running the broker on each MQTT node on both Pi.

I was honestly shown to use "hostname -I" to find the IP address. I'm on my public university wi-fi

Did you verify that the two devices can "see" each other? Can you ping from one to the other and back?

Yes, use the same IP on both pi’s. But as @gerry mentioned the IP addresses for a local network should begin with 10…, 192… or 172….

From the cli on pi-a make sure you can ping pi-b. Use:
ping-c 3 ip-address-goes-here

to jump in here. Yes, the Pi that has the broker setup is the IP for the other Pi. On the Pi that has the broker you did set up the MQTT node by assigning an id to it. I usually use 127.0.0.1 but you can also use the device IP as well. The other Pi the MQTT node setup uses the brokers IP of 142.x.x.x

[edit] it's possible there might be some type of port blocking as well, I think everything is on the table at this point

I might've got my numbers mixed up, sorry. I'll verify just to make sure in an hour when I go back to the college. I'm betting it is 172.#.#.#

So to just to go through each step so I can understand, if I'm trying to send a variable from Pi-A to Pi-B with Pi-B running MQTT broker that is receiving information, I complete this node below on Pi-B with the IP Address on the node assigning to the IP address of Pi-B.

image

I then implement the node below on Pi-A, which wants to send information to Pi-B, and I assign that node's IP address to the IP address of Pi-B

image

And this is with matching the topics together, ensuring that everything is updated, and if I can ping an IP address.

@gerry @zenofmud Also thank you for your help, I'll try all of this within the hour. I was trying extremely hard and I think I was confusing myself with something simple.

just as a note: if you put an # (pound sign) in the receive topic it will show all the messages regardless of topic, this will let you check to see if there is a topic issue.

If you want to learn more about MQTT then see this tutorial MQTT Essentials - All Core Concepts explained

@zenofmud @dceejay @gerry hello again, I'm still trying to get my MQTT to work, but on my second screen, I still can't get a response or connection on my second Pi. I have my first Pi sending a message to itself, but my second pi is still connecting.

My server for the first Pi with Node Red and MQTT broker running on it is 172.25.#.#(port number) which is what I put into my other Pi. I checked the Ping via the command line and it looks to be working.



y

Can you post a screen shot of the node configs?

Open a cli on pi-a and run:
Sudo cat /etc/mosquitto/mosquitto.conf
And copy the results and paste them to a response. Please do not show us a photo.

They on each pi, export your flow and paste it into a response