How to use different IPs with mqtt

Hi all
I am very new to node-red and have a simple question(to some). I have two Raspberry pi's that I want to monitor from my windows laptop, I have set up a flow but I cant seem to use the two different pi IP addresses. the all change to the same IP when I enter them
flows (1).json (22.2 KB)
Any help would be appreciated

I can't look at your flow, as I am on my phone. Are you running one MQTT broker or two?

For future reference you should paste flows inline see this post for more details - How to share code or flow json

You should have one mqtt broker and it will have an IP address. This broker could be installed on eithor Pi or a seperate Pi (I have mine installed on a Pi Zero W). The IP address of the machine that has the broker is the one you will enter when configuring the mqtt nodes on both pi's.

There is a great series of tutorial posts you should read if you want to learn more about MQTT at MQTT Essentials - All Core Concepts explained

I think your understanding of MQTT maybe incorrect. As the name suggests, a broker sits in the middle of all parties. You really only need one broker and you point every device at the one single broker. The way to differentiate messages is through using different topics.

This diagram may help...

I think that diagram might be slightly out-of-date as the current (best practice) way of setting a 'topic' doesn't start with a forward slash (as it adds a extra level of hierachy that isn't needed).

1 Like

Good point and absolutely correct - well spotted Dave.

I have two, each on its own pi

Ok so there is no other way to do it but to use something like that poses another problem in that if one pi goes down does not show that the one is down. Or is there another way I can perhaps achieve my goal. As I said I am very new to node-red

Ahhh ok I'll give that a try

Just looked at your flow.
All I can see are MQTT-In nodes (subscribe nodes). There are no MQTT-Out nodes (publish nodes).


I suggest you try creating a very simple flow to check if Mosquitto is working... like this...



That is ok, there is no problem with having a broker on each pi, that is what I usually do. When you configure the brokers in the mqtt nodes you have to use Add new server to add the second one, so you have two in the drop-down list. One for each pi.

Thank you all for the prompt replies. I have it all sorted. I was getting hung up on the one broker thing.

1 Like

Sorry, very curious. What are the advantages of this and how do you use them?

Advantage of what? Having a broker on each machine? If that is what you mean then it is so that the local control in the machine is not dependent on the network being up. I keep the current state of dashboard switches and other system state variables in MQTT Retained topics so it is necessary to have mosquitto always available. This means that if a Pi is controlling my heating system, for example, it will keep going even if the network is down.

For communication between the different Pis you can use MQTT Bridging which provides synchronisation of selected topics between the different brokers. Then the flow itself does not need to know which topics come from a different machine, they are all available in the local broker. How bridging works is well described in this blog Mosquitto MQTT Bridge-Usage and Configuration

1 Like

Yes that is what I was asking. Thank you, something for me to think about even if I do not use your 'retained' strategy.

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