# One node-red device to ctl another node-red device

**URL:** <https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449>\
**Category:** General\
**Created:** [28 May 2018 13:27 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449 "2018-05-28T13:27:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbond](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbond/32/38851_2.png) [@gbond](https://discourse.nodered.org/u/gbond)\
**Post date:** [28 May 2018 13:27 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/1 "2018-05-28T13:27:30Z")

</div>

is there a way to get one node red to send commands to another node-red device

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [28 May 2018 13:40 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/2 "2018-05-28T13:40:23Z")

</div>

Cross posted - [https://node-red.slack.com/archives/C03M2TAQ8/p1527514230000511](https://node-red.slack.com/archives/C03M2TAQ8/p1527514230000511)

---

<div class="post-metadata">

**Author:** ![asandford](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asandford](https://discourse.nodered.org/u/asandford)\
**Post date:** [28 May 2018 15:47 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/3 "2018-05-28T15:47:26Z")

</div>

I’d imagine MQTT would be the simplest if the flows are running on different machines

---

<div class="post-metadata">

**Author:** ![gbond](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbond/32/38851_2.png) [@gbond](https://discourse.nodered.org/u/gbond)\
**Post date:** [29 May 2018 13:45 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/4 "2018-05-29T13:45:55Z")

</div>

hi  
I am sure it would if only I could get my head around it  
did try to load mqtt my server 2012 but it failed  
I only want to read a sensor from one drive and do something on another & I just don’t find this node-red stuff very easy to understand (not looking at doing anything cloud based either)

---

<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:** [29 May 2018 14:39 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/5 "2018-05-29T14:39:11Z")

</div>

Well MQTT is, as far as I know, the easiest way to get data between parts of a node-red system. Start here [https://www.hivemq.com/mqtt-essentials/](https://www.hivemq.com/mqtt-essentials/)

Once you have read that and understood the basics then if you can’t get it running you can ask here.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [29 May 2018 14:58 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/6 "2018-05-29T14:58:10Z")

</div>

> [@gbond](#):
>
> I just don’t find this node-red stuff very easy to understand

Some of it isn't and it is quite different to other methods (such as traditional programming languages)

But if you think about it, how easy would it be to get get a program on one computer to send a message to another computer using a traditional programming language?

Quite hard.  
MQTT is considered a really good way of passing messages between computers

Here are example flows of sending and receiving a message via a public MQTT broker

`[{"id":"89481906.6eedf8","type":"inject","z":"e03a15ac.7a2328","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":140,"wires":[["eaecf0ac.de2eb"]]},{"id":"eaecf0ac.de2eb","type":"mqtt out","z":"e03a15ac.7a2328","name":"","topic":"cymplecy/timestamp","qos":"","retain":"true","broker":"b045d3bf.c4b8a","x":600,"y":140,"wires":[]},{"id":"93c8e193.5b8a9","type":"mqtt in","z":"e03a15ac.7a2328","name":"","topic":"cymplecy/timestamp","qos":"2","broker":"b045d3bf.c4b8a","x":300,"y":260,"wires":[["b7dbe4fe.aaf0c8"]]},{"id":"b7dbe4fe.aaf0c8","type":"debug","z":"e03a15ac.7a2328","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":580,"y":260,"wires":[]},{"id":"b045d3bf.c4b8a","type":"mqtt-broker","z":"","name":"","broker":"broker.hivemq.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]`

---

<div class="post-metadata">

**Author:** ![asandford](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asandford](https://discourse.nodered.org/u/asandford)\
**Post date:** [29 May 2018 15:10 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/7 "2018-05-29T15:10:52Z")

</div>

[RabbitMQ](https://www.rabbitmq.com/getstarted.html) is a good cross-platform, open-source, ‘local’ broker (supports many protocols as well as MQTT).

---

<div class="post-metadata">

**Author:** ![tilleul](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tilleul/32/78_2.png) [@tilleul](https://discourse.nodered.org/u/tilleul)\
**Post date:** [29 May 2018 15:32 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/8 "2018-05-29T15:32:44Z")

</div>

Well, it all depends on what you want to do exactly but if MQTT is too hard, why not use simple HTTP requests ?  
This method is “node-red-ready” as it does not require any additional software like a MQTT broker …  
Create a flow on NodeRed #1 including a “HTTP IN” node  
Create another flow NodeRed #2 sending an HTTP request to the http path defined on NodeRed #1 …

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [29 May 2018 15:58 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/9 "2018-05-29T15:58:50Z")

</div>

> [@gbond](#):
>
> I am sure it would if only I could get my head around it  
> did try to load mqtt my server 2012 but it failed  
> I only want to read a sensor from one drive and do something on another & I just don’t find this node-red stuff very easy to understand (not looking at doing anything cloud based either)

Maybe it would help if you explained in a little more detail. What setup do you have? It looks like you are using Windows Server? Are the 2 Node-RED instances actually on different devices?

Answers to these questions would help us focus in on some possible solutions.

There are loads of tutorials on installing the Mosquitto MQTT broker for example, but mainly on Linux. Windows isn't really any harder but is a slightly different when you want to productionize it.

---

<div class="post-metadata">

**Author:** ![gbond](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbond/32/38851_2.png) [@gbond](https://discourse.nodered.org/u/gbond)\
**Post date:** [29 May 2018 16:42 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/10 "2018-05-29T16:42:00Z")

</div>

ok  
want to keep it simple and in house  
I have a pi zero on ip address 192.168.7.80:1880 which reads a sensor etc (infred diodie)  
using node red  
I then have another pi zero also running node-red on ip-address 192.168.7.81:1880 which has a motor on it which again I can control

I want a reliable way to get the sensor from the 1st one turning the motor etc on the second one which I am sure is fairly straight forward.  
but im not very good with linx (far to used to Microsoft & networking at ip level)

I have pc servers that could host things if need be but eclipse MQTT did not seem to like server 2012 etc.

hope this is a bit clearer

---

<div class="post-metadata">

**Author:** ![asandford](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asandford](https://discourse.nodered.org/u/asandford)\
**Post date:** [29 May 2018 17:03 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/11 "2018-05-29T17:03:30Z")

</div>

To install the broker on either of the PIs:  
sudo apt-get update && sudo apt-get install -y mosquitto

You can install the clients on both with:  
sudo apt-get update && sudo apt-get install -y mosquitto-clients

Assuming you installed the broker on 192.168.7.80…

On 192.168.7.80, open a terminal and type:  
mosquitto\_sub -d -t hello/world

On 192.168.7.81, open a terminal and type:  
mosquitto\_pub -d -h 192.168.7.80 -t hello/world -m “Hello from 192.168.7.81”

This should result in something like below in the terminal on 192.168.7.80

Hello from 192.168.7.81

Once you’ve got that working, using MQTT is just as easy in NR.

---

<div class="post-metadata">

**Author:** ![gbond](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbond/32/38851_2.png) [@gbond](https://discourse.nodered.org/u/gbond)\
**Post date:** [29 May 2018 17:46 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/12 "2018-05-29T17:46:46Z")

</div>

ok thanks I will have a play

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [29 May 2018 17:57 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/13 "2018-05-29T17:57:33Z")

</div>

> [@gbond](#):
>
> I just don't find this node-red stuff very easy to understand

It is in fact very easy once you get more "warmed up". There is a learning curve as usual. As with everything in life. Training for a driver license, training & experience to make your girlfriend/wife happier, etc etc

But sometimes the forest is hidden by all the trees (A saying in my country)

But I can tell you, it works very well. Exactly what you wanna do I do but with other messages and other devices to control. Rock solid.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [29 May 2018 20:06 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/14 "2018-05-29T20:06:51Z")

</div>

> [@gbond](#):
>
> I have a pi zero on ip address 192.168.7.80:1880 which reads a sensor etc (infred diodie)  
> using node red  
> I then have another pi zero also running node-red on ip-address 192.168.7.81:1880 which has a motor on it which again I can control
> 
> I want a reliable way to get the sensor from the 1st one turning the motor etc on the second one which I am sure is fairly straight forward.  
> but im not very good with linx (far to used to Microsoft & networking at ip level)
> 
> I have pc servers that could host things if need be but eclipse MQTT did not seem to like server 2012 etc.

Right, I can see that there are lots of external dependencies for running Mosquitto on Windows. You would probably be better off with RabbitMQ or EMQ ([emqtt.io](http://emqtt.io)). Mosquitto is favoured by Pi users due to its low resource requirements.

But one of your Pi Zero's should be fine - just don't try to create too big a set of Node-RED flows. If you find the Pi0 getting slow or cranky due to low resources or high CPU, simply add another Pi0 just to run Mosquitto. It should go without saying that you should adjust the startup of the Pi to exclude the Linux GUI as this takes up loads of resources you don't need to use. I don't use a zero but I've had a reasonably complex set of Node-RED flows along with Mosquitto and a database running on an original Pi without any issues.

@asandford has given you the basics for installation. There are plenty of other tutorials around as well.

A really good source for learning about MQTT is the HiveMQ Essentials documentation ([MQTT Essentials - All Core Concepts Explained](https://www.hivemq.com/mqtt-essentials/)).

At first all you really need to remember is that MQTT is a publish and subscribe message handler (think email for machines). In Node-RED, you use the msg.topic to control the MQTT topic that you publish or subscribe to.

You might also want to grab a copy of MQTT Spy ([Home · eclipse/paho.mqtt-spy Wiki · GitHub](https://github.com/eclipse/paho.mqtt-spy/wiki)) which is a Java based (we try not to hold that against it!) cross-platform GUI tool that will let you easily explore your MQTT broker.

---

<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:** [29 May 2018 20:16 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/15 "2018-05-29T20:16:40Z")

</div>

A pi zero will easily handle node-red and mosquitto provided you do not have hundreds of nodes or hundreds of messages/second.

---

<div class="post-metadata">

**Author:** ![gbond](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbond/32/38851_2.png) [@gbond](https://discourse.nodered.org/u/gbond)\
**Post date:** [30 May 2018 09:20 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/16 "2018-05-30T09:20:13Z")

</div>

Thank you  
very helpful I will look into this

---

<div class="post-metadata">

**Author:** ![gbond](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbond/32/38851_2.png) [@gbond](https://discourse.nodered.org/u/gbond)\
**Post date:** [30 May 2018 14:25 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/17 "2018-05-30T14:25:28Z")

</div>

hi  
have just tried this  
is this secure & can you just send what ever you like across it (apart from needing internet access to use it ) whats the advantage in set a local broker up?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [30 May 2018 15:10 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/18 "2018-05-30T15:10:15Z")

</div>

Its not secure (as its a public broker - people just use it for convenience and testing )

You can send what you like ( within normal MQTT restraints)

The advantage is that it doesn’t need setting up 🙂

Another alternative, is to install the node-red-contrib-mqtt-broker and just run that on one of the Pi

Examples attached

Sending Pi

`[{"id":"94e9199b.e746a8","type":"inject","z":"768dfbdd.ae43a4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":140,"wires":[["45565d46.f8a2b4"]]},{"id":"45565d46.f8a2b4","type":"mqtt out","z":"768dfbdd.ae43a4","name":"","topic":"cymplecy/timestamp","qos":"","retain":"true","broker":"6711f1f2.75f57","x":580,"y":140,"wires":[]},{"id":"ca85b417.4a96d8","type":"mosca in","z":"768dfbdd.ae43a4","mqtt_port":"1883","mqtt_ws_port":8080,"name":"","username":"","password":"","dburl":"","x":270,"y":80,"wires":[[]]},{"id":"6711f1f2.75f57","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]`

receiving Pi  
(change IP to be the address of the sending Pi)

`[{"id":"6e223577.bc14bc","type":"mqtt in","z":"768dfbdd.ae43a4","name":"","topic":"cymplecy/timestamp","qos":"2","broker":"4fb8043.49c20fc","x":280,"y":260,"wires":[["8d67a7b4.987368"]]},{"id":"8d67a7b4.987368","type":"debug","z":"768dfbdd.ae43a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":560,"y":260,"wires":[]},{"id":"4fb8043.49c20fc","type":"mqtt-broker","z":"","name":"","broker":"aaa.bbb.ccc.ddd","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]`

---

<div class="post-metadata">

**Author:** ![asandford](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asandford](https://discourse.nodered.org/u/asandford)\
**Post date:** [30 May 2018 20:39 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/19 "2018-05-30T20:39:05Z")

</div>

> [@cymplecy](#):
>
> node-red-contrib-mqtt-broker

Thanks for the heads-up on that, [here's](https://www.youtube.com/watch?v=_P6ZqWc4n3I) a video by Peter Scargill demonstrating it.

---

<div class="post-metadata">

**Author:** ![gbond](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbond/32/38851_2.png) [@gbond](https://discourse.nodered.org/u/gbond)\
**Post date:** [30 May 2018 23:46 UTC](https://discourse.nodered.org/t/one-node-red-device-to-ctl-another-node-red-device/449/20 "2018-05-30T23:46:29Z")

</div>

Thank you so much. it became so much clearer with the example code that you have supplied

I have managed to get the two board to communicate (using the cloud base one so far)

most helpfull
