Hello
I'm very new to NodeRed, having been introduced to it via openHAB2
I also have a company that distrubutes Velbus hardware, so I have customers that want to have a nice dashboard or UI for their hardware.
One installer asked me if it were possible to link two instances of NodeRed, which has lead me to a lot of reading and not very many "simple" solutions.
So I took it upon myself to create something that "works", I'm not saying it's secure or robust, maybe even has some limitations that I don't fully understand yet, but I though that I might share it here as an alternative for those that just want something simple.
I would welcome any feedback and constructive critisim.
So the premise is that there are two (or more) machines on a local network that are running NodeRed (for reasons that I'm still not entirely sure of, but I'm sure I will be educated at some point)
I understand that one NodeRed instance needs to send simple messages to the other NodeRed instance.
On the sending machine, I have setup a TCP OUT mode, that connects to a port on the Receiving machine.
Messages are contructed in such a way that they can be split at the receiving machine.
For example, an ON & OFF message would be prefixed with an ID number.
- 1:ON
- 1:OFF
This set of nodes does this and sends it to port 9000 on the receiving machine
[
{
"id": "efa5d89c.7614a8",
"type": "tcp out",
"z": "bcd03685.5bead8",
"host": "192.168.178.42",
"port": "9000",
"beserver": "client",
"base64": false,
"end": true,
"name": "",
"x": 570,
"y": 260,
"wires": []
},
{
"id": "5bdd1cf.5a6ece4",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "1:ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 90,
"y": 80,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "7bceec6c.f97e94",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "1:OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 80,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "c5731b25.6cd4d8",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "2:ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 90,
"y": 200,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "3519eb3b.a58484",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "2:OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 200,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "ca510eba.dded8",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "3:ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 90,
"y": 320,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "52764144.e71c7",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "3:OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 320,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "7a5127ac.66a918",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "4:ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 90,
"y": 440,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "65f003fc.48103c",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "4:OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 250,
"y": 440,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "458954ee.1aacfc",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "4:1",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 90,
"y": 480,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "7f152040.5afb9",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "4:2",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 250,
"y": 480,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "391ccb68.eb00b4",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "4:1.5",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 90,
"y": 520,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "fe69ee81.62e2b",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "3:Words Man, lots of words",
"topic": "",
"payload": "3:Words Man, lots of words",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 170,
"y": 360,
"wires": [
[
"efa5d89c.7614a8"
]
]
},
{
"id": "84bc4061.2cc19",
"type": "function",
"z": "bcd03685.5bead8",
"name": "Add prefix of \"5:\"",
"func": "msg.payload = \"5:\"+(msg.payload);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 280,
"y": 640,
"wires": [
[
"af5c76ca.c36b28",
"efa5d89c.7614a8"
]
]
},
{
"id": "dafc80e3.a3e67",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 80,
"y": 620,
"wires": [
[
"84bc4061.2cc19"
]
]
},
{
"id": "e8375d6d.727fd",
"type": "inject",
"z": "bcd03685.5bead8",
"name": "",
"topic": "",
"payload": "ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 80,
"y": 660,
"wires": [
[
"84bc4061.2cc19"
]
]
},
{
"id": "af5c76ca.c36b28",
"type": "debug",
"z": "bcd03685.5bead8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 270,
"y": 740,
"wires": []
}
]
The receiving machine simply splits the messages up according to the Prefix.
[
{
"id": "810a0394.2f0d6",
"type": "function",
"z": "a4fb5176.e214b",
"name": "Split incoming message",
"func": "var input = String(msg.payload);\nvar msgOUT = (msg.payload);\nmsg.payload = input;\n\n\nvar inputSplit = input.split(\":\");\n\nvar port = inputSplit[0];\nmsgOUT = {payload:inputSplit[1]};\n\nif (port == 1 ) { \n return [msgOUT,null, null, null, null];\n\t}\n\t\nif (port == 2 ) { \n return [null, msgOUT, null, null, null];\n\t}\n\nif (port == 3 ) { \n return [null, null, msgOUT,null, null];\n\t}\n\t\nif (port == 4 ) { \n return [null, null, null, msgOUT, null];\n\t}\t\n\n\nif (port == 5 ) { \n return [null, null, null, null, msgOUT];\n\t}\n\nreturn [ null, null, null, null ];",
"outputs": 5,
"noerr": 0,
"x": 170,
"y": 560,
"wires": [
[
"f5b7cb75.eb3c18"
],
[
"1a4458de.d91057"
],
[
"c5beafaa.974ef"
],
[
"9475a5a0.83e4e8"
],
[
"8dc17d6d.57e4a"
]
]
},
{
"id": "f5b7cb75.eb3c18",
"type": "debug",
"z": "a4fb5176.e214b",
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 370,
"y": 480,
"wires": []
},
{
"id": "1a4458de.d91057",
"type": "debug",
"z": "a4fb5176.e214b",
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 590,
"y": 500,
"wires": []
},
{
"id": "9cd60081.4be",
"type": "tcp in",
"z": "a4fb5176.e214b",
"name": "",
"server": "server",
"host": "",
"port": "9000",
"datamode": "single",
"datatype": "utf8",
"newline": ":",
"topic": "",
"base64": false,
"x": 100,
"y": 420,
"wires": [
[
"fbc125d3.c1b368",
"810a0394.2f0d6"
]
]
},
{
"id": "c5beafaa.974ef",
"type": "debug",
"z": "a4fb5176.e214b",
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 410,
"y": 540,
"wires": []
},
{
"id": "9475a5a0.83e4e8",
"type": "debug",
"z": "a4fb5176.e214b",
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 610,
"y": 580,
"wires": []
},
{
"id": "8dc17d6d.57e4a",
"type": "debug",
"z": "a4fb5176.e214b",
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 410,
"y": 660,
"wires": []
},
{
"id": "fbc125d3.c1b368",
"type": "debug",
"z": "a4fb5176.e214b",
"d": true,
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 350,
"y": 420,
"wires": []
}
]
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.
If the needs of this installer's project are more complex, I'll point them to MQTT.
I hope that this helps someone else who just wants something really simple.