Hi guys, I have a problem that I don't understand at all.
First to understand the situation:
My programs works by going on a dashboard and by selecting a variable. When this variable is selected the list number is returned so that the modbus flex getter go search at the right place the value of this variable. This value is than joined in an object with the list number and kept in a msg.payload for later use.
This object is than put in the flow so that the function node can use it.
The function node works by getting an int number, putting it as a boolean number and then via the list number, choosing the right bit to show on the dashboard.
here's the debug:
So when I select a value in the dashboard going from 0 to 16 the program will work properly but when the value is bigger it will print me this undefined. And I don't understand why it stops working when the list number of the dashboard is bigger than 16.
[
{
"id": "ad42f873412c2f98",
"type": "tab",
"label": "RPI Shelter EIA",
"disabled": false,
"info": "",
"env": []
},
{
"id": "5bad0cb6533899a8",
"type": "ui_button",
"z": "ad42f873412c2f98",
"name": "",
"group": "780cfd9c93f7b572",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"label": "Lire",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 90,
"y": 740,
"wires": [
[
"e85dee5092aec692"
]
]
},
{
"id": "6817ad78d442051b",
"type": "ui_button",
"z": "ad42f873412c2f98",
"name": "",
"group": "18997b9d48e95027",
"order": 1,
"width": 0,
"height": 0,
"passthru": true,
"label": "INITIALISATION",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "date",
"topic": "topic",
"topicType": "msg",
"x": 120,
"y": 320,
"wires": [
[
"f56948d866932748"
]
]
},
{
"id": "f56948d866932748",
"type": "file in",
"z": "ad42f873412c2f98",
"name": "RequĂȘte1",
"filename": "C:\\Users\\Theodros\\Documents\\GRTgaz\\NODE-RED_GRTgaz\\Tables modbus\\Requete1 bool.csv",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 360,
"y": 320,
"wires": [
[
"1e304abcae2ccf65"
]
]
},
{
"id": "1e304abcae2ccf65",
"type": "csv",
"z": "ad42f873412c2f98",
"name": "",
"sep": ",",
"hdrin": false,
"hdrout": "all",
"multi": "mult",
"ret": "\\r\\n",
"temp": "label",
"skip": "0",
"strings": true,
"include_empty_strings": "",
"include_null_values": "",
"x": 510,
"y": 320,
"wires": [
[
"3500365835d5d8ac"
]
]
},
{
"id": "3500365835d5d8ac",
"type": "function",
"z": "ad42f873412c2f98",
"name": "REMPLISSAGE",
"func": "msg.options = msg.payload.map((el, index) => {\n\nreturn { [el.label] : index }\n \n})\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 680,
"y": 320,
"wires": [
[
"b4cd49f83874842e"
]
]
},
{
"id": "b4cd49f83874842e",
"type": "ui_dropdown",
"z": "ad42f873412c2f98",
"name": "",
"label": "",
"tooltip": "",
"place": "Select option",
"group": "780cfd9c93f7b572",
"order": 3,
"width": 0,
"height": 0,
"passthru": true,
"multiple": false,
"options": [],
"payload": "",
"topic": "S1",
"topicType": "str",
"className": "",
"x": 880,
"y": 320,
"wires": [
[
"a02a3e6a86c1ea6f",
"1dd903ddc2f6e1dd"
]
]
},
{
"id": "cf3418e05735fbd7",
"type": "ui_text",
"z": "ad42f873412c2f98",
"group": "780cfd9c93f7b572",
"order": 1,
"width": 6,
"height": 1,
"name": "",
"label": "BOOL",
"format": "{{msg.payload}}",
"layout": "col-center",
"className": "",
"x": 350,
"y": 260,
"wires": []
},
{
"id": "0eaf9f8b5014fd0f",
"type": "ui_text",
"z": "ad42f873412c2f98",
"group": "780cfd9c93f7b572",
"order": 4,
"width": 0,
"height": 0,
"name": "BOOL",
"label": "",
"format": "{{msg.payload}}",
"layout": "col-center",
"className": "",
"x": 1070,
"y": 740,
"wires": []
},
{
"id": "f80557635255a803",
"type": "function",
"z": "ad42f873412c2f98",
"name": "Adressage",
"func": "const num = msg.payload.S1; //Chiffre allant de 0 à 79\nconst val = msg.payload.B1[0]; // booléen\n\nnewArr=[]; //crée un nouveau tableau\n\nbit = val.toString(2).padStart(16,\"0\") ; //transforme le résultat sous forme de binaire\ntab = bit.split('');//sépare chaque chiffre\n\n//On inverse le tableau afin que les valeurs soit dans le bon sens\nfor(let i = tab.length - 1; i>=0; i--)\n{\n newArr.push(tab[i]);\n}\n\nmsg.payload = newArr[num];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 670,
"y": 740,
"wires": [
[
"0eaf9f8b5014fd0f",
"bc7cb18204d747dc"
]
]
},
{
"id": "a02a3e6a86c1ea6f",
"type": "function",
"z": "ad42f873412c2f98",
"name": "modbus flex getter options",
"func": "const num = msg.payload; //Chiffre allant de 0 Ă 78\n\nconst parsedInput = { WORD_OFFSET: Math.floor(num / 16) }\n\nmsg.payload= {\n 'fc': 3,\n 'unitid': 1,\n 'address': 59 + parsedInput.WORD_OFFSET,\n 'quantity': 1,\n}\nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 960,
"y": 480,
"wires": [
[
"b562440633b74130"
]
]
},
{
"id": "b562440633b74130",
"type": "modbus-flex-getter",
"z": "ad42f873412c2f98",
"name": "",
"showStatusActivities": false,
"showErrors": false,
"logIOActivities": false,
"server": "7d0292a23936c0ce",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"x": 1220,
"y": 480,
"wires": [
[
"09e7a16b624a6065"
],
[]
]
},
{
"id": "09e7a16b624a6065",
"type": "change",
"z": "ad42f873412c2f98",
"name": "",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "B1",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1440,
"y": 480,
"wires": [
[
"1dd903ddc2f6e1dd"
]
]
},
{
"id": "d872c1545f718544",
"type": "change",
"z": "ad42f873412c2f98",
"name": "",
"rules": [
{
"t": "set",
"p": "selected",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1650,
"y": 320,
"wires": [
[]
]
},
{
"id": "1dd903ddc2f6e1dd",
"type": "join",
"z": "ad42f873412c2f98",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "1",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 1420,
"y": 320,
"wires": [
[
"d872c1545f718544"
]
]
},
{
"id": "f78c38bb795f3c5c",
"type": "modbus-server",
"z": "ad42f873412c2f98",
"name": "",
"logEnabled": false,
"hostname": "0.0.0.0",
"serverPort": 10502,
"responseDelay": 100,
"delayUnit": "ms",
"coilsBufferSize": 10000,
"holdingBufferSize": 10000,
"inputBufferSize": 10000,
"discreteBufferSize": 10000,
"showErrors": false,
"x": 640,
"y": 100,
"wires": [
[],
[],
[],
[],
[]
]
},
{
"id": "e85dee5092aec692",
"type": "change",
"z": "ad42f873412c2f98",
"name": "Envoie des données",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "selected",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 300,
"y": 740,
"wires": [
[
"f80557635255a803",
"b07658c8cddfcebd"
]
]
},
{
"id": "bc7cb18204d747dc",
"type": "debug",
"z": "ad42f873412c2f98",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 930,
"y": 580,
"wires": []
},
{
"id": "b07658c8cddfcebd",
"type": "debug",
"z": "ad42f873412c2f98",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 390,
"y": 540,
"wires": []
},
{
"id": "8a43d090e4c4e17a",
"type": "ui_spacer",
"z": "ad42f873412c2f98",
"name": "spacer",
"group": "780cfd9c93f7b572",
"order": 5,
"width": 6,
"height": 1
},
{
"id": "2d8e385d43e906c7",
"type": "ui_spacer",
"z": "ad42f873412c2f98",
"name": "spacer",
"group": "780cfd9c93f7b572",
"order": 10,
"width": 6,
"height": 1
},
{
"id": "373285ef2508ebc9",
"type": "ui_spacer",
"z": "ad42f873412c2f98",
"name": "spacer",
"group": "780cfd9c93f7b572",
"order": 15,
"width": 6,
"height": 1
},
{
"id": "ba8e0a9132cd1daf",
"type": "ui_spacer",
"z": "ad42f873412c2f98",
"name": "spacer",
"group": "15528da52822872e",
"order": 6,
"width": 6,
"height": 1
},
{
"id": "7ad12eb46dbba9d7",
"type": "ui_spacer",
"z": "ad42f873412c2f98",
"name": "spacer",
"group": "15528da52822872e",
"order": 12,
"width": 6,
"height": 1
},
{
"id": "780cfd9c93f7b572",
"type": "ui_group",
"name": "RequĂȘte 1",
"tab": "0baea998ce75eabd",
"order": 1,
"disp": true,
"width": 6,
"collapse": false,
"className": ""
},
{
"id": "18997b9d48e95027",
"type": "ui_group",
"name": "INITIALISATION",
"tab": "0baea998ce75eabd",
"order": 4,
"disp": true,
"width": 8,
"collapse": false,
"className": ""
},
{
"id": "7d0292a23936c0ce",
"type": "modbus-client",
"name": "",
"clienttype": "tcp",
"bufferCommands": true,
"stateLogEnabled": false,
"queueLogEnabled": false,
"tcpHost": "0.0.0.0",
"tcpPort": "10502",
"tcpType": "DEFAULT",
"serialPort": "/dev/ttyUSB",
"serialType": "RTU-BUFFERD",
"serialBaudrate": "9600",
"serialDatabits": "8",
"serialStopbits": "1",
"serialParity": "none",
"serialConnectionDelay": "100",
"serialAsciiResponseStartDelimiter": "0x3A",
"unit_id": "1",
"commandDelay": "1",
"clientTimeout": "1000",
"reconnectOnTimeout": true,
"reconnectTimeout": "2000",
"parallelUnitIdsAllowed": true
},
{
"id": "15528da52822872e",
"type": "ui_group",
"name": "RequĂȘte 3",
"tab": "0baea998ce75eabd",
"order": 3,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "0baea998ce75eabd",
"type": "ui_tab",
"name": "RPI Shelter EIA",
"icon": "RPI Shelter EIA",
"disabled": false,
"hidden": false
}
]
PS: Hope what I said is understandable, don't hesitate on correcting me or asking questions