# How to use different IPs with mqtt

**URL:** <https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785>\
**Category:** General\
**Created:** [30 October 2022 07:07 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785 "2022-10-30T07:07:14Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaunfish](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shaunfish/32/51095_2.png) [@shaunfish](https://discourse.nodered.org/u/shaunfish)\
**Post date:** [30 October 2022 07:07 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/1 "2022-10-30T07:07:14Z")

</div>

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](https://discourse.nodered.org/uploads/short-url/4RBlbuxkrb2z5FlWOINHbFdwn71.json) (22.2 KB)  
Any help would be appreciated  
Regards  
Shaun

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2022 07:21 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/2 "2022-10-30T07:21:36Z")

</div>

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](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [30 October 2022 07:30 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/3 "2022-10-30T07:30:23Z")

</div>

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](https://www.hivemq.com/mqtt-essentials/)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 October 2022 07:33 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/4 "2022-10-30T07:33:37Z")

</div>

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...

 ![Screenshot_20221030-073401](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/163cee1cfe08f3c2dbd8a1edc178b27d7520664c.jpeg)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [30 October 2022 08:00 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/5 "2022-10-30T08:00:16Z")

</div>

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).  
 ![mqtt_topic_slash](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/42077c95be5fc3886cce9ae5f1a7b65a45e8ea42.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 October 2022 08:01 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/6 "2022-10-30T08:01:26Z")

</div>

Good point and absolutely correct - well spotted Dave.

---

<div class="post-metadata">

**Author:** ![shaunfish](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shaunfish/32/51095_2.png) [@shaunfish](https://discourse.nodered.org/u/shaunfish)\
**Post date:** [30 October 2022 08:32 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/7 "2022-10-30T08:32:18Z")

</div>

I have two, each on its own pi

---

<div class="post-metadata">

**Author:** ![shaunfish](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shaunfish/32/51095_2.png) [@shaunfish](https://discourse.nodered.org/u/shaunfish)\
**Post date:** [30 October 2022 08:38 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/8 "2022-10-30T08:38:15Z")

</div>

Ok so there is no other way to do it but to use something like [test.mosquitto.org](http://test.mosquitto.org). that poses another problem in that if one pi goes down [test.mosquitto.org](http://test.mosquitto.org) 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

---

<div class="post-metadata">

**Author:** ![shaunfish](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shaunfish/32/51095_2.png) [@shaunfish](https://discourse.nodered.org/u/shaunfish)\
**Post date:** [30 October 2022 08:40 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/9 "2022-10-30T08:40:11Z")

</div>

Ahhh ok I'll give that a try

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [30 October 2022 08:42 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/10 "2022-10-30T08:42:14Z")

</div>

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

![just_in_nodes](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6afe408f24abd5029be22c9881ecc23aee16e6f8.png)

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

![test_A](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/dffcbd74524b85e5a907c250c63289a03d9513da.png)

![test_B](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f1478ed89b56c1272c5e098cf65ffc23362f047.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2022 08:58 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/11 "2022-10-30T08:58:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shaunfish](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shaunfish/32/51095_2.png) [@shaunfish](https://discourse.nodered.org/u/shaunfish)\
**Post date:** [30 October 2022 11:10 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/12 "2022-10-30T11:10:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [30 October 2022 15:26 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/13 "2022-10-30T15:26:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2022 16:12 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/14 "2022-10-30T16:12:57Z")

</div>

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](http://www.steves-internet-guide.com/mosquitto-bridge-configuration/)

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [30 October 2022 17:32 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/15 "2022-10-30T17:32:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 December 2022 17:33 UTC](https://discourse.nodered.org/t/how-to-use-different-ips-with-mqtt/69785/16 "2022-12-29T17:33:22Z")

</div>

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