Hello,
I read data from an electronic card integrated in a climatic chamber.
I use the node-red-contrib-telnet-client to do that (I can't use s7 nodes for example).
Because we have multiples chambers, I created an object (in a function) where there is the list of the chambers with their own properties (IP address, name, port). In the telnet nodes, I would like to inject these parameters in the fields, and not directly a value. In fact, I would like to establish the connection for one chamber, then read and treat data, and finally wait a little in order to do this cycle for each chamber (the delay is here for avoiding communication saturation).
How could I make a loop for this ? I just have to change the 3 fields in the "Connection" field of the telnet node. For instance, in the "Port" field in the telnet node, I can only put a number value. I can not enter a parameter like "msg.payload.port".
Here is my function with the list of the chambers :
let Etuves = {
nomEtuve: "",
adresseIP: "",
port: 888,
}
let etuve217 = Object.create(Etuves);
etuve217.nomEtuve = "Etuve 217";
etuve217.adresseIP = "xx.xx.xx.217";
let etuve109 = Object.create(Etuves);
etuve109.nomEtuve = "Etuve 109";
etuve109.adresseIP = "xx.xx.xx.109";
let etuve111 = Object.create(Etuves);
etuve111.nomEtuve = "Etuve 111";
etuve111.adresseIP = "xx.xx.xx.111";
let etuve216 = Object.create(Etuves);
etuve216.nomEtuve = "Etuve 216";
etuve216.adresseIP = "xx.xx.xx.216";
let tab = [];
tab.push(etuve217)
tab.push(etuve109)
tab.push(etuve111)
tab.push(etuve216)
return {payload: tab}
You will find below the flow :
[
{
"id": "1a7e315fd340af0f",
"type": "tab",
"label": "Flow 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "a8c1d9281aea0673",
"type": "function",
"z": "1a7e315fd340af0f",
"name": "List of the chambers",
"func": "let Etuves = {\n nomEtuve: \"\",\n adresseIP: \"\",\n port: 888,\n}\n\n\n\nlet etuve217 = Object.create(Etuves);\netuve217.nomEtuve = \"Etuve 217\";\netuve217.adresseIP = \"xx.xx.xx.217\";\n\n\nlet etuve109 = Object.create(Etuves);\netuve109.nomEtuve = \"Etuve 109\";\netuve109.adresseIP = \"xx.xx.xx.109\";\n\n\nlet etuve111 = Object.create(Etuves);\netuve111.nomEtuve = \"Etuve 111\";\netuve111.adresseIP = \"xx.xx.xx.111\";\n\n\nlet etuve216 = Object.create(Etuves);\netuve216.nomEtuve = \"Etuve 216\";\netuve216.adresseIP = \"xx.xx.xx.216\";\n\n\nlet tab = [];\ntab.push(etuve217)\ntab.push(etuve109)\ntab.push(etuve111)\ntab.push(etuve216)\n\nreturn {payload: tab}\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 600,
"y": 360,
"wires": [
[
"133e8899145a6ab6",
"a690ba198e52db7e"
]
]
},
{
"id": "32fa05f1e9c7c923",
"type": "inject",
"z": "1a7e315fd340af0f",
"name": "Fake Data",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "56",
"payloadType": "num",
"x": 400,
"y": 360,
"wires": [
[
"a8c1d9281aea0673"
]
]
},
{
"id": "2b5a428a194e0fc4",
"type": "debug",
"z": "1a7e315fd340af0f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1050,
"y": 280,
"wires": []
},
{
"id": "133e8899145a6ab6",
"type": "change",
"z": "1a7e315fd340af0f",
"name": "",
"rules": [
{
"t": "set",
"p": "listeEtuves",
"pt": "global",
"to": "tab",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 860,
"y": 360,
"wires": [
[
"2b5a428a194e0fc4",
"16e8c2f9e428e79c"
]
]
},
{
"id": "a690ba198e52db7e",
"type": "debug",
"z": "1a7e315fd340af0f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 830,
"y": 280,
"wires": []
},
{
"id": "4cc7ebb845e3a096",
"type": "telnet-send",
"z": "1a7e315fd340af0f",
"name": "",
"connection": "27ace6a62991b9b0",
"x": 1230,
"y": 360,
"wires": []
},
{
"id": "a4df93d5b4be84e1",
"type": "telnet-read",
"z": "1a7e315fd340af0f",
"name": "",
"connection": "",
"x": 1230,
"y": 420,
"wires": [
[
"e1a6047482ce5f0e"
]
]
},
{
"id": "e1a6047482ce5f0e",
"type": "debug",
"z": "1a7e315fd340af0f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1390,
"y": 420,
"wires": []
},
{
"id": "16e8c2f9e428e79c",
"type": "delay",
"z": "1a7e315fd340af0f",
"name": "",
"pauseType": "delay",
"timeout": "10",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 1070,
"y": 360,
"wires": [
[
"4cc7ebb845e3a096"
]
]
},
{
"id": "27ace6a62991b9b0",
"type": "telnet-connection",
"name": "",
"address": "127.0.0.1",
"port": "23",
"inDelimiter": "",
"outDelimiter": "",
"timeOut": "1500",
"clearOut": "",
"openTries": "1"
}
]
I am still a beginner in Javascript, so maybe there is a more efficient way to do this function.
Thank you for your help