# Linking 2 or more instances on a local network

**URL:** <https://discourse.nodered.org/t/linking-2-or-more-instances-on-a-local-network/24879>\
**Category:** General\
**Created:** [15 April 2020 11:11 UTC](https://discourse.nodered.org/t/linking-2-or-more-instances-on-a-local-network/24879 "2020-04-15T11:11:29Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [15 April 2020 12:51 UTC](https://discourse.nodered.org/t/linking-2-or-more-instances-on-a-local-network/24879/3 "2020-04-15T12:51:05Z")

</div>

> [@MDAR](#):
>
> I appreciate that adding a MQTT server might have been easier, but as I don't know anything about MQTT, I thought I should try something else.

It would have been easier and more future proofing to read up on MQTT (IMO).

Heres the 30sec intro...

> MQTT is a Client Server publish/subscribe messaging transport protocol. It is light weight, open, simple, and designed so as to be easy to implement"

- An MQTT client (node-red / IoT sensor / whatever) `publish`es to an MQTT `broker`
  - a `topic` and `payload` are sent in each publish
    - a topic is a string e.g. "house/bedroom/light" or "machine/1/motor/speed"
    - a payload is anything you want (boolean `true` / string `'on'` / JSON `'{"i_am_a_property" : "I am a value"}'` )

- anyone `subscribe`d to the same topic will get the payload published

#### You can even run the whole thing in node-red...

- install node-red-contrib-aedes from the pallet
- import this...

```auto
[{"id":"7ef0c0cb.93e75","type":"aedes broker","z":"5396dbf2.571004","name":"","mqtt_port":1883,"mqtt_ws_port":"","cert":"","key":"","certname":"","keyname":"","dburl":"","usetls":false,"x":370,"y":100,"wires":[[]]},{"id":"d400ab1c.e5aa98","type":"comment","z":"5396dbf2.571004","name":"NODE RED Server 1","info":"","x":380,"y":60,"wires":[]},{"id":"d0e47698.475c88","type":"comment","z":"5396dbf2.571004","name":"NODE RED Server 2 (lets just pretend)","info":"","x":430,"y":360,"wires":[]},{"id":"bca7954b.6c6f38","type":"mqtt in","z":"5396dbf2.571004","name":"subscribe only to test/topic","topic":"test/topic","qos":"2","datatype":"auto","broker":"4af1f016.58aaa","x":390,"y":160,"wires":[["90624683.dd7b48"]]},{"id":"90624683.dd7b48","type":"debug","z":"5396dbf2.571004","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":160,"wires":[]},{"id":"c3ef294f.bd5848","type":"inject","z":"5396dbf2.571004","name":"","topic":"test/topic","payload":"hello from server 2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":420,"wires":[["c828a72a.c256f8"]]},{"id":"c828a72a.c256f8","type":"mqtt out","z":"5396dbf2.571004","name":"","topic":"","qos":"","retain":"","broker":"4af1f016.58aaa","x":630,"y":420,"wires":[]},{"id":"4003927f.a8358c","type":"inject","z":"5396dbf2.571004","name":"","topic":"test/motor/speed","payload":"180","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":480,"wires":[["c828a72a.c256f8"]]},{"id":"f21dcebf.1490b","type":"inject","z":"5396dbf2.571004","name":"send multiple values in JSON","topic":"test/data","payload":"{\"name\":\"lucky number\",\"value\":7}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":540,"wires":[["c828a72a.c256f8"]]},{"id":"172cfdaa.6e2622","type":"mqtt in","z":"5396dbf2.571004","name":"subscribe to everything after test/","topic":"test/#","qos":"2","datatype":"auto","broker":"4af1f016.58aaa","x":410,"y":200,"wires":[["b17c801a.a37b"]]},{"id":"b17c801a.a37b","type":"debug","z":"5396dbf2.571004","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":200,"wires":[]},{"id":"fc86b9d3.1de028","type":"inject","z":"5396dbf2.571004","name":"","topic":"server1/test","payload":"hello from server 1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":430,"y":260,"wires":[["43565974.6592e8"]]},{"id":"43565974.6592e8","type":"mqtt out","z":"5396dbf2.571004","name":"","topic":"","qos":"","retain":"","broker":"4af1f016.58aaa","x":630,"y":260,"wires":[]},{"id":"db24acf8.d8462","type":"mqtt in","z":"5396dbf2.571004","name":"subscribe to server1/test","topic":"server1/test","qos":"2","datatype":"auto","broker":"4af1f016.58aaa","x":410,"y":600,"wires":[["7a5973a9.7577ec"]]},{"id":"7a5973a9.7577ec","type":"debug","z":"5396dbf2.571004","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":600,"wires":[]},{"id":"4af1f016.58aaa","type":"mqtt-broker","z":"","name":"aedes local","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"40","cleansession":true,"birthTopic":"aedes/state","birthQos":"0","birthPayload":"ready","closeTopic":"aedes/state","closeQos":"0","closePayload":"alert","willTopic":"aedes/state","willQos":"0","willPayload":"alert"}]

```

#### Bingo...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c4217455e336bf86a6e980655e74070a55c8e5c8.png)

---

_[View the full topic](https://discourse.nodered.org/t/linking-2-or-more-instances-on-a-local-network/24879)._
