But as soon as i connect "Küche Arbeitsplatte" to "Modbus_1" i got this Error:
i am using Modbus TCP Node to communicate with my Wago PLC. Everything works fine until i connect another modbus node in my flow. Here it looks like:
var x = [0,0,0,0,0,0,0,0,0,0,0,0,0];var msg_o = [msg,msg,msg,msg,msg,msg,msg,msg,msg,msg,msg,msg,msg];for(i=0;i<13; i++){ x[i] = msg.payload[i]; if(x[i]===true){ msg_o[i] = {payload: true}; }else{ msg_o[i] = {payload: false}; }}return msg_o;
// build an array of msgs, mapping topics to registers
var msgs = [
{ topic: "Lichter/HWR", payload: msg.payload[0] },
{ topic: "Lichter/Windfang", payload: msg.payload[1] },
{ topic: "Lichter/WC", payload: msg.payload[2] },
{ topic: "Lichter/Buero", payload: msg.payload[3] },
...
{ topic: "Lichter/Flur", payload: msg.payload[12] }
];
// send the whole array of msgs to the output port
return [msgs];
[{"id":"f1f5cfe3.970f8","type":"function","z":"c02bb355.ee4ae","name":"Lichter_EG","func":"var x = [0,0,0,0,0,0,0,0,0,0,0,0,0];\nvar msg_o = [msg,msg,msg,msg,msg,msg,msg,msg,msg,msg,msg,msg,msg];\nfor(i=0;i<13; i++){\n x[i] = msg.payload[i];\n if(x[i]===true){\n msg_o[i] = {payload: true};\n }else{\n msg_o[i] = {payload: false}; \n }\n}\nreturn msg_o;","outputs":"13","noerr":0,"x":470,"y":240,"wires":[["8cbaabbe.1e6168"],["5128873d.aaaf38"],["53d423a2.3515bc"],["d7e93fb9.7c8bb"],["70770261.5ec5dc"],["f74d030c.0a409"],["7cce786a.fa66a8"],["76731d2.7ec2fe4"],["6bb2eae4.773bc4"],["324fee70.649e42"],["a8ce92e4.117ac"],[],[]]},{"id":"8cbaabbe.1e6168","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"HWR","group":"ad22dbee.a216c8","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"HWR","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":710,"y":40,"wires":[["edc9156c.bbd998"]]},{"id":"d7e93fb9.7c8bb","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Buero","group":"ad22dbee.a216c8","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Buero","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":710,"y":160,"wires":[["edc9156c.bbd998"]]},{"id":"e9a194bb.bee1b8","type":"comment","z":"c02bb355.ee4ae","name":"Daten von Wago PLC über Modbus auslesen","info":"","x":190,"y":40,"wires":[]},{"id":"5128873d.aaaf38","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Windfang","group":"ad22dbee.a216c8","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Windfang","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":720,"y":80,"wires":[["edc9156c.bbd998"]]},{"id":"53d423a2.3515bc","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"WC","group":"ad22dbee.a216c8","order":3,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"WC","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":710,"y":120,"wires":[["edc9156c.bbd998"]]},{"id":"70770261.5ec5dc","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Küche Mitte","group":"ad22dbee.a216c8","order":7,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Kueche_mitte","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":730,"y":200,"wires":[["edc9156c.bbd998"]]},{"id":"f74d030c.0a409","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Küche Arbeitsplatte","group":"ad22dbee.a216c8","order":6,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Kueche_arbeitsplatte","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":750,"y":240,"wires":[["edc9156c.bbd998"]]},{"id":"7cce786a.fa66a8","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Esszimmer","group":"ad22dbee.a216c8","order":8,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Esszimmer","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":730,"y":280,"wires":[["edc9156c.bbd998"]]},{"id":"76731d2.7ec2fe4","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Esszimmer Wand","group":"ad22dbee.a216c8","order":9,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Esszimmer_wand","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":750,"y":320,"wires":[["edc9156c.bbd998"]]},{"id":"6bb2eae4.773bc4","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Wohnzimmer","group":"ad22dbee.a216c8","order":10,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Wohnzimmer","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":730,"y":360,"wires":[["edc9156c.bbd998"]]},{"id":"324fee70.649e42","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Wohnzimmer Wand","group":"ad22dbee.a216c8","order":11,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Wohnzimmer_wand","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":750,"y":400,"wires":[["edc9156c.bbd998"]]},{"id":"a8ce92e4.117ac","type":"ui_switch","z":"c02bb355.ee4ae","name":"","label":"Flur","group":"ad22dbee.a216c8","order":5,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"Flur","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":710,"y":440,"wires":[["edc9156c.bbd998"]]},{"id":"6cc7af6f.b8e63","type":"modbustcp-read","z":"c02bb355.ee4ae","name":"Modbus_Lichter_EG","dataType":"Coil","adr":"17088","quantity":"13","rate":"2","rateUnit":"s","server":"c28c9bdc.97aa08","x":190,"y":240,"wires":[["f1f5cfe3.970f8"]]},{"id":"edc9156c.bbd998","type":"function","z":"c02bb355.ee4ae","name":"Lichter_EG_Write","func":"// build an array of msgs, mapping topics to registers\nvar msgs = [\n { topic: \"HWR\", payload: msg.payload[0] },\n { topic: \"Windfang\", payload: msg.payload[1] },\n { topic: \"WC\", payload: msg.payload[2] },\n { topic: \"Buero\", payload: msg.payload[3] },\n { topic: \"Kueche_mitte\", payload: msg.payload[4] },\n { topic: \"Kueche_arbeitsplatte\", payload: msg.payload[5] },\n { topic: \"Esszimmer\", payload: msg.payload[6] },\n { topic: \"Esszimmer_wand\", payload: msg.payload[7] },\n { topic: \"Wohnzimmer\", payload: msg.payload[8] },\n { topic: \"Wohnzimmer_wand\", payload: msg.payload[9] },\n { topic: \"Flur\", payload: msg.payload[10] }\n];\n\n// send the whole array of msgs to the output port\nreturn [msgs];","outputs":1,"noerr":0,"x":1120,"y":240,"wires":[["127c20a7.869f4f"]]},{"id":"127c20a7.869f4f","type":"debug","z":"c02bb355.ee4ae","name":"","active":true,"console":"false","complete":"false","x":1320,"y":240,"wires":[]},{"id":"ad22dbee.a216c8","type":"ui_group","z":"","name":"Beleuchtung","tab":"7fd8e76c.53e588","order":1,"disp":true,"width":"6"},{"id":"c28c9bdc.97aa08","type":"modbustcp-server","z":"","host":"10.23.59.10","port":"502","unit_id":"1","reconnecttimeout":""},{"id":"7fd8e76c.53e588","type":"ui_tab","z":"","name":"Erdgeschoss","icon":"dashboard","order":2}]
[ { "id": "29fb65d3.7d321a", "type": "tab", "label": "Lichter switch", "disabled": false, "info": "" }, { "id": "573708d1.6a86d8", "type": "ui_switch", "z": "29fb65d3.7d321a",
"name": "", "label": "HWR",
"group": "8c33c2e4.11f4e",
"order": 1, "width": 0, "height": 0, "passthru": true, "decouple": "false",
"topic": "Lichter/HWR", "style": "", "onvalue": "1", "onvalueType": "str", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "str", "officon": "", "offcolor": "", "x": 410, "y": 280, "wires": [ [ "e647e749.22ae18", "e05b831f.508d1" ] ] }, { "id": "4a060f4f.3595", "type": "ui_switch", "z": "29fb65d3.7d321a",
"name": "", "label": "Buero",
"group": "8c33c2e4.11f4e",
"order": 4, "width": 0, "height": 0, "passthru": true, "decouple": "false",
"topic": "Lichter/Buero", "style": "", "onvalue": "1", "onvalueType": "str", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "str", "officon": "", "offcolor": "", "x": 410, "y": 400, "wires": [ [ "e647e749.22ae18" ] ] }, { "id": "57f56c0b.da7fb4", "type": "ui_switch", "z": "29fb65d3.7d321a",
"name": "", "label": "Windfang",
"group": "8c33c2e4.11f4e",
"order": 2, "width": 0, "height": 0, "passthru": true, "decouple": "false",
"topic": "Lichter/Windfang", "style": "", "onvalue": "1", "onvalueType": "str", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "str", "officon": "", "offcolor": "", "x": 420, "y": 320, "wires": [ [ "e647e749.22ae18" ] ] }, { "id": "8b70ea34.375578", "type": "ui_switch", "z": "29fb65d3.7d321a",
"name": "", "label": "WC",
"group": "8c33c2e4.11f4e",
"order": 3, "width": 0, "height": 0, "passthru": true, "decouple": "false",
"topic": "Lichter/WC", "style": "", "onvalue": "1", "onvalueType": "str", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "str", "officon": "", "offcolor": "", "x": 410, "y": 360, "wires": [ [ "e647e749.22ae18" ] ] }, { "id": "e665e232.c08b2", "type": "function", "z": "29fb65d3.7d321a", "name": "build coil array", "func": "// build an array of values from the msg.topic\nvar topics = [ \"HWR\", \"Windfang\", \"WC\", \"Buero\" ];\nvar zeros = topics.map(function (d) { return 0 });\nvar topic = msg.topic.split(\"/\")[1] || \"Unknown\";\nvar index = topics.indexOf(topic);\nif (index < 0) return null;\n\n// update the register for the incoming switch\nvar value = +msg.payload; // convert to number\nvar coils = flow.get(\"registers\") || zeros;\ncoils[index] = value;\nnode.status({ \"text\": topics[index] + (value? \" (on)\": \" (off)\") });\n\n// send the array of coil values to the output port\nmsg.payload = coils;\nreturn msg;", "outputs": 1, "noerr": 0, "x": 440, "y": 560, "wires": [ [ "9868a2f2.a3a2c" ] ] }, { "id": "6714ada3.ab4f64", "type": "debug", "z": "29fb65d3.7d321a",
"name": "", "active": true, "console": "false", "complete": "false",
"x": 670, "y": 560, "wires": [] }, { "id": "ecb29ce0.b9b4f", "type": "inject", "z": "29fb65d3.7d321a", "name": "coil register values", "topic": "Lichter", "payload": "[ 0, 0, 1, 0 ]", "payloadType": "json", "repeat": "", "crontab": "", "once": false, "x": 190, "y": 120, "wires": [ [ "1726e448.7a60ec" ] ] }, { "id": "661a5bfc.e44a74", "type": "comment", "z": "29fb65d3.7d321a", "name": "Read the coils and split the values by position", "info": "", "x": 270, "y": 60, "wires": [] }, { "id": "62d3f145.95a16", "type": "comment", "z": "29fb65d3.7d321a", "name": "Display the switches to match the coil values", "info": "", "x": 270, "y": 220, "wires": [] }, { "id": "66f04e77.72608", "type": "comment", "z": "29fb65d3.7d321a", "name": "Update the coils whenever any switch changes", "info": "", "x": 280, "y": 500, "wires": [] }, { "id": "1726e448.7a60ec", "type": "function", "z": "29fb65d3.7d321a", "name": "map coils to topics", "func": "// get the parent topic from the plc read node\nvar top = msg.topic || \"Lichter\";\n\n// build an array of msgs, mapping topics to registers\nvar msgs = [\n { topic: top+\"/HWR\", payload: msg.payload[0] },\n { topic: top+\"/Windfang\", payload: msg.payload[1] },\n { topic: top+\"/WC\", payload: msg.payload[2] },\n { topic: top+\"/Buero\", payload: msg.payload[3] }\n];\n\n// send the whole array of msgs to the output port\nreturn [msgs];", "outputs": 1, "noerr": 0, "x": 430, "y": 120, "wires": [ [ "48b51556.81517c", "52f223dc.3c445c" ] ] }, { "id": "48b51556.81517c", "type": "mqtt out", "z": "29fb65d3.7d321a", "name": "", "topic": "", "qos": "2", "retain": "true", "broker": "ec93534d.af15b", "x": 650, "y": 120, "wires": [] }, { "id": "84dee794.a9eb28", "type": "mqtt in", "z": "29fb65d3.7d321a", "name": "", "topic": "Lichter/HWR", "qos": "2", "broker": "ec93534d.af15b", "x": 210, "y": 280, "wires": [ [ "573708d1.6a86d8" ] ] }, { "id": "b015796e.a30e88", "type": "mqtt in", "z": "29fb65d3.7d321a", "name": "", "topic": "Lichter/Windfang", "qos": "2", "broker": "ec93534d.af15b", "x": 200, "y": 320, "wires": [ [ "57f56c0b.da7fb4" ] ] }, { "id": "c9987303.1d402", "type": "mqtt in", "z": "29fb65d3.7d321a", "name": "", "topic": "Lichter/WC", "qos": "2", "broker": "ec93534d.af15b", "x": 220, "y": 360, "wires": [ [ "8b70ea34.375578" ] ] }, { "id": "1c09a9f3.dc4406", "type": "mqtt in", "z": "29fb65d3.7d321a", "name": "", "topic": "Lichter/Buero", "qos": "2", "broker": "ec93534d.af15b", "x": 210, "y": 400, "wires": [ [ "4a060f4f.3595" ] ] }, { "id": "e647e749.22ae18", "type": "mqtt out", "z": "29fb65d3.7d321a", "name": "", "topic": "", "qos": "2", "retain": "true", "broker": "ec93534d.af15b", "x": 650, "y": 340, "wires": [] }, { "id": "70a51df8.4211e4", "type": "mqtt in", "z": "29fb65d3.7d321a", "name": "", "topic": "Lichter/+", "qos": "2", "broker": "ec93534d.af15b", "x": 220, "y": 560, "wires": [ [ "e665e232.c08b2" ] ] }, { "id": "9b1abf93.7c591", "type": "change", "z": "29fb65d3.7d321a", "name": "save register array", "rules": [ { "t": "set", "p": "registers", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 690, "y": 620, "wires": [ [] ] }, { "id": "52f223dc.3c445c", "type": "debug", "z": "29fb65d3.7d321a",
"name": "", "active": true, "console": "false", "complete": "false",
"x": 670, "y": 180, "wires": [] }, { "id": "e05b831f.508d1", "type": "debug", "z": "29fb65d3.7d321a",
"name": "", "active": true, "console": "false", "complete": "false",
"x": 670, "y": 280, "wires": [] }, { "id": "9868a2f2.a3a2c", "type": "delay", "z": "29fb65d3.7d321a", "name": "", "pauseType": "rate", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": true, "x": 450, "y": 620, "wires": [ [ "9b1abf93.7c591", "6714ada3.ab4f64" ] ] }, { "id": "8c33c2e4.11f4e",
"type": "ui_group", "z": "", "name": "Beleuchtung",
"tab": "deb6edfa.18e2c",
"order": 1, "disp": true, "width": "6" }, {
"id": "ec93534d.af15b", "type": "mqtt-broker", "z": "", "broker": "localhost", "port": "1883", "clientid": "", "usetls": false, "compatmode": true, "keepalive": "15", "cleansession": true, "willTopic": "", "willQos": "0", "willPayload": "", "birthTopic": "", "birthQos": "0", "birthPayload": "" }, { "id": "deb6edfa.18e2c",
"type": "ui_tab", "z": "", "name": "Erdgeschoss", "icon": "dashboard", "order": 2 }]
Hi Steve,
i´ve tried your function. I got on every msg.payload "undefined".