Hello All,
Today is my first day!
I am using Node RED since a few weeks only.
I have an array of values coming from Modbus RTU. I am able to read 4 objects under one array "payload.addressSpaceItems[2].nodeId". THe four objects are given as: see " myisssue 1.jpeg"
What I want to do is to create a single variable in whihc the value of 4 objects shoudl be shpown as 1111.
I have tried "join" and also "parser" but did not mamange to get a single value.
Thanking youin advance for your help
Here is the code:
[
{
"id": "cef6e0716e26e027",
"type": "tab",
"label": "Array to word",
"disabled": false,
"info": "",
"env": []
},
{
"id": "2b2b6e7c0ab3712e",
"type": "OPCUA-IIoT-Response",
"z": "cef6e0716e26e027",
"name": "CMD",
"compressStructure": true,
"showStatusActivities": false,
"showErrors": false,
"activateUnsetFilter": false,
"activateFilters": false,
"negateFilter": false,
"filters": [],
"x": 1170,
"y": 400,
"wires": [
[
"43da5b273301c159"
]
]
},
{
"id": "43da5b273301c159",
"type": "debug",
"z": "cef6e0716e26e027",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1350,
"y": 400,
"wires": []
},
{
"id": "6ded65f94816977d",
"type": "OPCUA-IIoT-Browser",
"z": "cef6e0716e26e027",
"nodeId": "",
"name": "Browse root",
"justValue": true,
"sendNodesToRead": false,
"sendNodesToBrowser": false,
"sendNodesToListener": false,
"multipleOutputs": false,
"showStatusActivities": false,
"showErrors": false,
"recursiveBrowse": true,
"recursiveDepth": "6",
"delayPerMessage": 0.2,
"connector": "041396811b8c7ab1",
"x": 350,
"y": 140,
"wires": [
[
"c3999f9e9c598aa2"
]
]
},
{
"id": "4014dda193b14206",
"type": "inject",
"z": "cef6e0716e26e027",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "30",
"crontab": "",
"once": true,
"onceDelay": "35",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 140,
"wires": [
[
"6ded65f94816977d"
]
]
},
{
"id": "0fc4c3f983d7998d",
"type": "function",
"z": "cef6e0716e26e027",
"name": "find node ids",
"func": "var name;\nvar part;\nvar part_tmp;\nvar id_value;\nvar ns, i;\n\n\nfor (var x in msg.payload.browserResults){\n console.log(x);\n console.log(msg.payload.browserResults[x].browseName);\n name = msg.payload.browserResults[x].browseName;\n if (name.includes(\"SFM_5_RunForward\")){\n flow.set('cmd_id',msg.payload.browserResults[x].nodeId);\n }\n if (name.includes(\"SFM_5_OSPValid\")){\n flow.set('osp_id',msg.payload.browserResults[x].nodeId);\n }\n \n if (name.includes(\"SFM_5_ResetErros\")){\n flow.set('RE_id',msg.payload.browserResults[x].nodeId);\n }\n \n \n\n \n //we are using DJTCN to read MVCH2\n if (name.includes(\"Zone1_TCN1\")){\n flow.set('temp_id',msg.payload.browserResults[x].nodeId);\n}\n //we are using B21 to read Energy /value\n if (name.includes(\"B21\")){\n flow.set('L1_id',msg.payload.browserResults[x].nodeId);\n}\n \n //we are using TCN2 - read SNO /value\n if (name.includes(\"Zone2_TCN2\")){\n flow.set('SNO_id',msg.payload.browserResults[x].nodeId);\n }\n \n\n}\nid_value = flow.get(\"temp_id\");\npart = id_value.split(\";\");\npart_tmp = part[0].split(\"=\");\nns = part_tmp[1];\n// reading mv ch2 /value from DJTCN and 80 is being offset from djtcn to mvch/value\npart_tmp = part[1].split(\"=\");\ni = Number(part_tmp[1]) + 80;\n// defining global variable with temp_id for mv ch 2\nflow.set('temp_id_mvch2',\"ns=\"+ ns+ \";i=\"+i);\n\n//setting i to id for mv ch 1 offfset 74\ni = Number(part_tmp[1]) + 74;\n// defining global variable with temp_id for mv ch 1\nflow.set('temp_id_mvch1',\"ns=\"+ ns+ \";i=\"+i);\n\n// reading energy from B21 50392 (B21)- 50430 (L1/value) = 38 is being offset from UMC toEnergy /value\nid_value = flow.get(\"L1_id\");\npart = id_value.split(\";\");\npart_tmp = part[1].split(\"=\");\ni = Number(part_tmp[1]) + 38;\nflow.set('L1_id',\"ns=\"+ ns+ \";i=\"+i);\n\n// reading SNO of Zone2 TCN2 50295- 50269 (SNO/value) = 26 is being offset from UMC toEnergy /value\nid_value = flow.get(\"SNO_id\");\npart = id_value.split(\";\");\npart_tmp = part[1].split(\"=\");\ni = Number(part_tmp[1]) + 26;\nflow.set('SNO_id',\"ns=\"+ ns+ \";i=\"+i);\n\n\n//exporting everything for debuging\n\nmsg.temp_id_mvch1 = flow.get(\"temp_id_mvch1\");\nmsg.temp_id_mvch2 = flow.get(\"temp_id_mvch2\");\nmsg.L1_id = flow.get(\"L1_id\");\nmsg.SNO_id = flow.get(\"SNO_id\");\n\nmsg.osp_id = flow.get(\"osp_id\");\nmsg.cmd_id = flow.get(\"cmd_id\");\nmsg.cmd_id = flow.get(\"RE_id\");\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 550,
"y": 140,
"wires": [
[]
]
},
{
"id": "b9527564bb86d79c",
"type": "debug",
"z": "cef6e0716e26e027",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 730,
"y": 180,
"wires": []
},
{
"id": "79641f1b1bf24b3f",
"type": "comment",
"z": "cef6e0716e26e027",
"name": "To convert array to word",
"info": "turn on if both gpios are true",
"x": 120,
"y": 60,
"wires": []
},
{
"id": "c3999f9e9c598aa2",
"type": "function",
"z": "cef6e0716e26e027",
"name": "find node ids",
"func": "var name;\nvar part;\nvar part_tmp;\nvar id_value;\nvar ns, i;\n\n\nfor (var x in msg.payload.browserResults){\n console.log(x);\n console.log(msg.payload.browserResults[x].browseName);\n name = msg.payload.browserResults[x].browseName;\n if (name.includes(\"SFM_5_RunForward\")){\n flow.set('cmd_id',msg.payload.browserResults[x].nodeId);\n }\n if (name.includes(\"SFM_5_OSPValid\")){\n flow.set('osp_id',msg.payload.browserResults[x].nodeId);\n }\n \n if (name.includes(\"SFM_5_ResetErros\")){\n flow.set('RE_id',msg.payload.browserResults[x].nodeId);\n }\n \n \n\n \n //we are using DJTCN to read MVCH2\n if (name.includes(\"Zone1_TCN1\")){\n flow.set('temp_id',msg.payload.browserResults[x].nodeId);\n}\n //we are using B21 to read Energy /value\n if (name.includes(\"B21\")){\n flow.set('B21_id',msg.payload.browserResults[x].nodeId);\n}\n \n //we are using TCN2 - read SNO /value\n if (name.includes(\"Zone2_TCN2\")){\n flow.set('SNO_id',msg.payload.browserResults[x].nodeId);\n }\n \n\n}\nid_value = flow.get(\"temp_id\");\npart = id_value.split(\";\");\npart_tmp = part[0].split(\"=\");\nns = part_tmp[1];\n// reading mv ch2 /value from DJTCN and 80 is being offset from djtcn to mvch/value\npart_tmp = part[1].split(\"=\");\ni = Number(part_tmp[1]) + 80;\n// defining global variable with temp_id for mv ch 2\nflow.set('temp_id_mvch2',\"ns=\"+ ns+ \";i=\"+i);\n\n//setting i to id for mv ch 1 offfset 74\ni = Number(part_tmp[1]) + 74;\n// defining global variable with temp_id for mv ch 1\nflow.set('temp_id_mvch1',\"ns=\"+ ns+ \";i=\"+i);\n\n// reading energy from B21 50392 (B21)- 50430 (L1/value) = 86 is the diffetnce is being offset from UMC toEnergy /value\nid_value = flow.get(\"B21_id\");\npart = id_value.split(\";\");\npart_tmp = part[1].split(\"=\");\ni = Number(part_tmp[1]) + 86;\nflow.set('L1_id',\"ns=\"+ ns+ \";i=\"+i);\n\n//setting i to id for AC Import offfset 32\ni = Number(part_tmp[1]) + 32;\n// defining global variable with ac import\nflow.set('aci_id',\"ns=\"+ ns+ \";i=\"+i);\n\n// reading SNO of Zone2 TCN2 50295- 50269 (SNO/value) = 26 is being offset from UMC toEnergy /value\nid_value = flow.get(\"SNO_id\");\npart = id_value.split(\";\");\npart_tmp = part[1].split(\"=\");\ni = Number(part_tmp[1]) + 26;\nflow.set('SNO_id',\"ns=\"+ ns+ \";i=\"+i);\n\n\n//exporting everything for debuging\n\nmsg.temp_id_mvch1 = flow.get(\"temp_id_mvch1\");\nmsg.temp_id_mvch2 = flow.get(\"temp_id_mvch2\");\nmsg.L1_id = flow.get(\"L1_id\");\nmsg.SNO_id = flow.get(\"SNO_id\");\n\nmsg.osp_id = flow.get(\"osp_id\");\nmsg.cmd_id = flow.get(\"cmd_id\");\nmsg.cmd_id = flow.get(\"RE_id\");\nmsg.aci_id = flow.get(\"aci_id\");\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 550,
"y": 80,
"wires": [
[
"b9527564bb86d79c"
]
]
},
{
"id": "70ea5289614eb08f",
"type": "OPCUA-IIoT-Inject",
"z": "cef6e0716e26e027",
"injectType": "read",
"payload": "",
"payloadType": "date",
"topic": "",
"repeat": "30",
"crontab": "",
"once": true,
"startDelay": "60",
"name": "Read temp Chan 2",
"addressSpaceItems": [
{
"name": "TempChan2",
"nodeId": "",
"datatypeName": ""
}
],
"x": 160,
"y": 280,
"wires": [
[
"7b5c07e3d317b7fa"
]
]
},
{
"id": "7b5c07e3d317b7fa",
"type": "change",
"z": "cef6e0716e26e027",
"name": "",
"rules": [
{
"t": "set",
"p": "payload.addressSpaceItems[0].nodeId",
"pt": "msg",
"to": "temp_id_mvch1",
"tot": "flow"
},
{
"t": "set",
"p": "payload.addressSpaceItems[1].nodeId",
"pt": "msg",
"to": "temp_id_mvch2",
"tot": "flow"
},
{
"t": "set",
"p": "payload.addressSpaceItems[2].nodeId",
"pt": "msg",
"to": "L1_id",
"tot": "flow"
},
{
"t": "set",
"p": "payload.addressSpaceItems[3].nodeId",
"pt": "msg",
"to": "SNO_id",
"tot": "flow"
},
{
"t": "set",
"p": "payload.addressSpaceItems[4].nodeId",
"pt": "msg",
"to": "osp_id",
"tot": "flow"
},
{
"t": "set",
"p": "payload.addressSpaceItems[5].nodeId",
"pt": "msg",
"to": "cmd_id",
"tot": "flow"
},
{
"t": "set",
"p": "payload.addressSpaceItems[6].nodeId",
"pt": "msg",
"to": "RE_id",
"tot": "flow"
},
{
"t": "set",
"p": "payload.addressSpaceItems[7].nodeId",
"pt": "msg",
"to": "aci_id",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 360,
"y": 260,
"wires": [
[
"026fdb9c13b34e98"
]
]
},
{
"id": "026fdb9c13b34e98",
"type": "OPCUA-IIoT-Read",
"z": "cef6e0716e26e027",
"attributeId": "13",
"maxAge": 1,
"depth": 1,
"connector": "041396811b8c7ab1",
"name": "Read Value",
"justValue": true,
"showStatusActivities": false,
"showErrors": false,
"parseStrings": false,
"historyDays": "",
"x": 550,
"y": 280,
"wires": [
[
"71814333c42f01ef",
"e31b530071bdd3d9"
]
]
},
{
"id": "71814333c42f01ef",
"type": "debug",
"z": "cef6e0716e26e027",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 790,
"y": 280,
"wires": []
},
{
"id": "49b7815078264a14",
"type": "function",
"z": "cef6e0716e26e027",
"name": "Array1",
"func": "msg.payload.value = msg.payload.value[2].value.value;\n\n\n\n\n\nreturn msg\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 670,
"y": 400,
"wires": [
[]
]
},
{
"id": "393a56951f9ece37",
"type": "change",
"z": "cef6e0716e26e027",
"name": "",
"rules": [
{
"t": "set",
"p": "a1",
"pt": "global",
"to": "payload.value",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 730,
"y": 460,
"wires": [
[]
]
},
{
"id": "acd8b058efa915d9",
"type": "debug",
"z": "cef6e0716e26e027",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 950,
"y": 460,
"wires": []
},
{
"id": "c03422c0e26e5dce",
"type": "function",
"z": "cef6e0716e26e027",
"name": "",
"func": "let combined = \"\" // Define combined as a string \nfor (let i = 0 ; i < msg.payload.length; i++) { // each array element\n combined += Math.abs(msg.payload[i]) //append it to the string\n}\nmsg.payload = combined\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 680,
"y": 580,
"wires": [
[
"acd8b058efa915d9"
]
]
},
{
"id": "8cc4e9a9d7e82638",
"type": "inject",
"z": "cef6e0716e26e027",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "cells",
"v": "Tabellenblatt1",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[1,2,3,4]",
"payloadType": "json",
"x": 240,
"y": 540,
"wires": [
[]
]
},
{
"id": "d983f2de5c92cc9b",
"type": "change",
"z": "cef6e0716e26e027",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{msg.payload.mvch2, msg.payload.mvch1,\t }\t",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 240,
"y": 440,
"wires": [
[
"c03422c0e26e5dce"
]
]
},
{
"id": "e31b530071bdd3d9",
"type": "change",
"z": "cef6e0716e26e027",
"name": "",
"rules": [
{
"t": "set",
"p": "timestamp",
"pt": "msg",
"to": "",
"tot": "date"
},
{
"t": "set",
"p": "temp_id_mvch1_value",
"pt": "flow",
"to": "payload.value.0.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.mvch1",
"pt": "msg",
"to": "payload.value.0.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "temp_id_mvch2_value",
"pt": "flow",
"to": "payload.value.1.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.mvch2",
"pt": "msg",
"to": "payload.value.1.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "L1_id_value",
"pt": "flow",
"to": "payload.value[2].value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.L1_id0",
"pt": "msg",
"to": "payload.value[2].value.value[0]",
"tot": "msg"
},
{
"t": "set",
"p": "payload.L1_id1",
"pt": "msg",
"to": "payload.value[2].value.value[1]",
"tot": "msg"
},
{
"t": "set",
"p": "SNO_id_value",
"pt": "flow",
"to": "payload.value.3.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.SNO_id",
"pt": "msg",
"to": "payload.value.3.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "cmd_id_value",
"pt": "flow",
"to": "payload.value.4.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.cmd_id",
"pt": "msg",
"to": "payload.value.4.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "osp_id_value",
"pt": "flow",
"to": "payload.value.5.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.osp_id",
"pt": "msg",
"to": "payload.value.5.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "RE_id_value",
"pt": "flow",
"to": "payload.value.6.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.RE_id",
"pt": "msg",
"to": "payload.value.6.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.aci_id",
"pt": "flow",
"to": "payload.value.7.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.aci_id",
"pt": "msg",
"to": "payload.value.7.value.value",
"tot": "msg"
},
{
"t": "set",
"p": "payload.aci_id0",
"pt": "msg",
"to": "payload.value[7].value.value[0]",
"tot": "msg"
},
{
"t": "set",
"p": "payload.aci_id1",
"pt": "msg",
"to": "payload.value[7].value.value[3]",
"tot": "msg"
},
{
"t": "set",
"p": "payload.RTime",
"pt": "msg",
"to": "RTime",
"tot": "flow"
},
{
"t": "set",
"p": "msg.payload.value[9].value.value",
"pt": "msg",
"to": "Too expensive",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 150,
"y": 380,
"wires": [
[
"d983f2de5c92cc9b"
]
]
},
{
"id": "041396811b8c7ab1",
"type": "OPCUA-IIoT-Connector",
"discoveryUrl": "",
"endpoint": "opc.tcp://localhost:4840",
"endpointMustExist": false,
"keepSessionAlive": true,
"loginEnabled": true,
"name": "LOCAL SERVER",
"showErrors": false,
"securityPolicy": "None",
"securityMode": "None",
"individualCerts": false,
"publicCertificateFile": "",
"privateKeyFile": "",
"defaultSecureTokenLifetime": "",
"autoSelectRightEndpoint": false,
"strategyMaxRetry": "",
"strategyInitialDelay": "",
"strategyMaxDelay": "",
"strategyRandomisationFactor": "",
"requestedSessionTimeout": "",
"connectionStartDelay": "",
"reconnectDelay": "",
"maxBadSessionRequests": "10"
}
]
haplc2000