I went ahead with the project and developed this method.
The problem is that looking at the debug the data acquisition is not regular every 10 seconds as set by me, every now and then every 30, every now and then a device is not read.
[
{
"id": "b5c38da134e475d3",
"type": "subflow",
"name": "Schneider NSX Legacy",
"info": "",
"category": "Multimetri Schneider",
"in": [
{
"x": 140,
"y": 320,
"wires": [
{
"id": "95020dfee2589cb7"
}
]
}
],
"out": [
{
"x": 680,
"y": 320,
"wires": [
{
"id": "8d1679d3d5343316",
"port": 0
}
]
},
{
"x": 700,
"y": 520,
"wires": [
{
"id": "5b83c0979c31cc07",
"port": 0
}
]
}
],
"env": [
{
"name": "ModBusID",
"type": "num",
"value": "",
"ui": {
"icon": "font-awesome/fa-caret-right",
"type": "input",
"opts": {
"types": [
"num"
]
}
}
}
],
"meta": {
"module": "Multimetri Z",
"version": "0.1",
"author": "ZEnergy"
},
"color": "#DEBD5C",
"outputLabels": [
"INT16U",
"Float32"
],
"icon": "node-red-contrib-modbus/modbus-icon.png"
},
{
"id": "19a96cc7d119c3de",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Concatenata L2-L3",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'V23',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12030, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 120,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "654ad2f8cc5fbbc6",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Concatenata L3-L1",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'V31',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12031, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 160,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "ca04e754fd3533a7",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Corrente I1",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'I1',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12015, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 350,
"y": 200,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "bd86442faff0272b",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Corrente I2",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'I2',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12016, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 350,
"y": 240,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "6aa8c08714e72f17",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Corrente I3",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'I3',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12017, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 350,
"y": 280,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "66d1ec7e4e56f835",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Potenza Attiva Totale",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'PAT',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12040, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 320,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "b093a8aa8484f3c3",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Potenza Reattiva Totale",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'PRT',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12044, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 360,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "efe0172a4cd5e3e0",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Potenza Apparente Totale",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'PApT',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12040, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 400,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "8fa3d56cefea82dd",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Fattore di Potenza Totale",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'FPT',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12098, \n 'quantity': 1 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 440,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "9793859c3b488c2f",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Energia Attiva Totale",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'EAT',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12049, \n 'quantity': 2 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 480,
"wires": [
[
"5b83c0979c31cc07"
]
]
},
{
"id": "96961418ee1c9553",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Energia Reattiva Totale",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'ERT',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12051, \n 'quantity': 2 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 520,
"wires": [
[
"5b83c0979c31cc07"
]
]
},
{
"id": "f2491cdde789dd5a",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Energia Apparente Totale",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'EApT',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12061, \n 'quantity': 2 \n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 560,
"wires": [
[
"5b83c0979c31cc07"
]
]
},
{
"id": "dcfab549a3a4ca9c",
"type": "function",
"z": "b5c38da134e475d3",
"name": "Concatenata L1-L2",
"func": "let ID = env.get(\"ModBusID\");\n\nmsg.payload = {\n 'value': 'V12',\n 'fc': 3, \n 'unitid': ID, \n 'address': 12029, \n 'quantity': 1\n} \nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 80,
"wires": [
[
"8d1679d3d5343316"
]
]
},
{
"id": "95020dfee2589cb7",
"type": "junction",
"z": "b5c38da134e475d3",
"x": 180,
"y": 320,
"wires": [
[
"f2491cdde789dd5a",
"96961418ee1c9553",
"9793859c3b488c2f",
"8fa3d56cefea82dd",
"efe0172a4cd5e3e0",
"b093a8aa8484f3c3",
"66d1ec7e4e56f835",
"6aa8c08714e72f17",
"bd86442faff0272b",
"ca04e754fd3533a7",
"654ad2f8cc5fbbc6",
"19a96cc7d119c3de",
"dcfab549a3a4ca9c"
]
]
},
{
"id": "8d1679d3d5343316",
"type": "junction",
"z": "b5c38da134e475d3",
"x": 580,
"y": 320,
"wires": [
[]
]
},
{
"id": "5b83c0979c31cc07",
"type": "junction",
"z": "b5c38da134e475d3",
"x": 620,
"y": 520,
"wires": [
[]
]
},
{
"id": "b9b68b463b4d9325",
"type": "inject",
"z": "b456a9d88b9efc5b",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "10",
"crontab": "",
"once": true,
"onceDelay": "10",
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 110,
"y": 700,
"wires": [
[
"1715273a3af8e128",
"310e3873c2bcce8e"
]
]
},
{
"id": "340ea44d3e221dfe",
"type": "debug",
"z": "b456a9d88b9efc5b",
"name": "debug 10",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 960,
"y": 880,
"wires": []
},
{
"id": "1931d5485093c185",
"type": "modbus-flex-getter",
"z": "b456a9d88b9efc5b",
"name": "",
"showStatusActivities": false,
"showErrors": false,
"showWarnings": true,
"logIOActivities": false,
"server": "4804d9b8eb93f5f9",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"delayOnStart": false,
"startDelayTime": "",
"x": 370,
"y": 720,
"wires": [
[
"48d09e589553fd1b"
],
[]
]
},
{
"id": "1715273a3af8e128",
"type": "subflow:b5c38da134e475d3",
"z": "b456a9d88b9efc5b",
"name": "Utenze meccaniche - 6",
"env": [
{
"name": "ModBusID",
"value": "6",
"type": "num"
}
],
"x": 140,
"y": 760,
"wires": [
[
"1931d5485093c185"
],
[
"fd53fc673ff05e45"
]
]
},
{
"id": "e6dea3ef49527c48",
"type": "function",
"z": "b456a9d88b9efc5b",
"name": "INT32U to INT16",
"func": "// Funzione per convertire un array [parte alta, parte bassa] in un numero INT32U\nfunction convertToInt32U(array) {\n // Assicurati che l'array contenga esattamente due elementi\n if (array.length !== 2) {\n return null; // Restituisci null se l'array non è valido\n }\n\n // Estrai la parte alta e bassa dell'INT32U dall'array\n var parteAlta = array[0];\n var parteBassa = array[1];\n\n // Calcola il numero INT32U\n var numeroInt32U = (parteAlta * 65536) + parteBassa;\n\n return numeroInt32U;\n}\n\n// Preleva l'array di input dal payload del nodo precedente\nvar inputArray = msg.payload;\n\n// Chiamata alla funzione di conversione\nvar risultato = convertToInt32U(inputArray);\n\n// Creazione dell'array con il valore convertito\nvar payloadArray = [risultato];\n\n// Creazione del nuovo oggetto di output\nvar outputMsg = {\n payload: payloadArray,\n modbusRequest: msg.modbusRequest, // Mantieni l'oggetto modbusRequest originale\n topic: msg.topic, // Mantieni il topic\n messageId: msg.messageId, // Mantieni il messageId\n queueLengthByUnitId: msg.queueLengthByUnitId, // Mantieni queueLengthByUnitId\n queueUnitId: msg.queueUnitId, // Mantieni queueUnitId\n unitId: msg.unitId, // Mantieni unitId\n responseBuffer: msg.responseBuffer, // Mantieni responseBuffer\n _msgid: msg._msgid // Mantieni _msgid\n};\n\n// Restituisci il messaggio con l'array nel payload e l'ID del messaggio\nreturn outputMsg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 840,
"wires": [
[
"48d09e589553fd1b"
]
]
},
{
"id": "fd53fc673ff05e45",
"type": "modbus-flex-getter",
"z": "b456a9d88b9efc5b",
"name": "",
"showStatusActivities": false,
"showErrors": false,
"showWarnings": true,
"logIOActivities": false,
"server": "4804d9b8eb93f5f9",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"delayOnStart": false,
"startDelayTime": "",
"x": 370,
"y": 780,
"wires": [
[
"e6dea3ef49527c48"
],
[]
]
},
{
"id": "310e3873c2bcce8e",
"type": "subflow:b5c38da134e475d3",
"z": "b456a9d88b9efc5b",
"name": "Impianto FTV - 5",
"env": [
{
"name": "ModBusID",
"value": "5",
"type": "num"
}
],
"x": 150,
"y": 1020,
"wires": [
[
"4f81ed714fc95851"
],
[
"f9e55f69b5e049f7"
]
]
},
{
"id": "4f81ed714fc95851",
"type": "modbus-flex-getter",
"z": "b456a9d88b9efc5b",
"name": "",
"showStatusActivities": false,
"showErrors": false,
"showWarnings": true,
"logIOActivities": false,
"server": "4804d9b8eb93f5f9",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"delayOnStart": false,
"startDelayTime": "",
"x": 370,
"y": 980,
"wires": [
[
"07dfbd18275bc6e0"
],
[]
]
},
{
"id": "07dfbd18275bc6e0",
"type": "join",
"z": "b456a9d88b9efc5b",
"name": "Join - modbusRequest.value",
"mode": "custom",
"build": "object",
"property": "",
"propertyType": "full",
"key": "modbusRequest.value",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "13",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 660,
"y": 1020,
"wires": [
[
"aba2d8e8ca1ecc6b"
]
]
},
{
"id": "f9e55f69b5e049f7",
"type": "modbus-flex-getter",
"z": "b456a9d88b9efc5b",
"name": "",
"showStatusActivities": false,
"showErrors": false,
"showWarnings": true,
"logIOActivities": false,
"server": "4804d9b8eb93f5f9",
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"delayOnStart": false,
"startDelayTime": "",
"x": 370,
"y": 1040,
"wires": [
[
"d80088a92bcf8da4"
],
[]
]
},
{
"id": "d80088a92bcf8da4",
"type": "function",
"z": "b456a9d88b9efc5b",
"name": "INT32U to INT16",
"func": "// Funzione per convertire un array [parte alta, parte bassa] in un numero INT32U\nfunction convertToInt32U(array) {\n // Assicurati che l'array contenga esattamente due elementi\n if (array.length !== 2) {\n return null; // Restituisci null se l'array non è valido\n }\n\n // Estrai la parte alta e bassa dell'INT32U dall'array\n var parteAlta = array[0];\n var parteBassa = array[1];\n\n // Calcola il numero INT32U\n var numeroInt32U = (parteAlta * 65536) + parteBassa;\n\n return numeroInt32U;\n}\n\n// Preleva l'array di input dal payload del nodo precedente\nvar inputArray = msg.payload;\n\n// Chiamata alla funzione di conversione\nvar risultato = convertToInt32U(inputArray);\n\n// Creazione dell'array con il valore convertito\nvar payloadArray = [risultato];\n\n// Creazione del nuovo oggetto di output\nvar outputMsg = {\n payload: payloadArray,\n modbusRequest: msg.modbusRequest, // Mantieni l'oggetto modbusRequest originale\n topic: msg.topic, // Mantieni il topic\n messageId: msg.messageId, // Mantieni il messageId\n queueLengthByUnitId: msg.queueLengthByUnitId, // Mantieni queueLengthByUnitId\n queueUnitId: msg.queueUnitId, // Mantieni queueUnitId\n unitId: msg.unitId, // Mantieni unitId\n responseBuffer: msg.responseBuffer, // Mantieni responseBuffer\n _msgid: msg._msgid // Mantieni _msgid\n};\n\n// Restituisci il messaggio con l'array nel payload e l'ID del messaggio\nreturn outputMsg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 1100,
"wires": [
[
"07dfbd18275bc6e0"
]
]
},
{
"id": "aba2d8e8ca1ecc6b",
"type": "function",
"z": "b456a9d88b9efc5b",
"name": "Costruzione JSon (String)",
"func": "var inputPayload = msg.payload;\nvar sampleEntry = {\n \"timestamp\": new Date().toISOString().split(\"T\")[0] + \" \" + new Date().toISOString().split(\"T\")[1].split(\".\")[0],\n \"dev\": String(inputPayload.I1.unitId) // Converte il valore in una stringa\n};\n\nObject.keys(inputPayload).forEach(function (key) {\n var entry = inputPayload[key];\n\n if (entry.payload) {\n // Converti l'array di byte in una stringa\n var stringValue = entry.payload.join(', ');\n sampleEntry[entry.modbusRequest.value] = stringValue;\n } else if (entry.responseBuffer && entry.responseBuffer.data) {\n // Converti l'array di byte in una stringa\n var stringValue = entry.responseBuffer.data.join(', ');\n sampleEntry[entry.modbusRequest.value] = stringValue;\n }\n});\n\nmsg.payload = {\n \"key\": inputPayload.I1.topic,\n \"samples\": [sampleEntry]\n};\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 880,
"wires": [
[
"0412750b05c06ac6"
]
]
},
{
"id": "0412750b05c06ac6",
"type": "json",
"z": "b456a9d88b9efc5b",
"name": "",
"property": "payload",
"action": "str",
"pretty": false,
"x": 850,
"y": 920,
"wires": [
[
"340ea44d3e221dfe"
]
]
},
{
"id": "48d09e589553fd1b",
"type": "join",
"z": "b456a9d88b9efc5b",
"name": "Join - modbusRequest.value",
"mode": "custom",
"build": "object",
"property": "",
"propertyType": "full",
"key": "modbusRequest.value",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "13",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 660,
"y": 760,
"wires": [
[
"aba2d8e8ca1ecc6b"
]
]
},
{
"id": "4804d9b8eb93f5f9",
"type": "modbus-client",
"name": "Tosano_Ittico",
"clienttype": "tcp",
"bufferCommands": true,
"stateLogEnabled": false,
"queueLogEnabled": false,
"failureLogEnabled": true,
"tcpHost": "172.20.18.11",
"tcpPort": "502",
"tcpType": "DEFAULT",
"serialPort": "/dev/ttyUSB",
"serialType": "RTU-BUFFERD",
"serialBaudrate": "9600",
"serialDatabits": "8",
"serialStopbits": "1",
"serialParity": "none",
"serialConnectionDelay": "100",
"serialAsciiResponseStartDelimiter": "0x3A",
"unit_id": "0",
"commandDelay": "1",
"clientTimeout": "1000",
"reconnectOnTimeout": true,
"reconnectTimeout": "2000",
"parallelUnitIdsAllowed": true,
"showWarnings": true,
"showLogs": true
}
]
Can anyone explain to me why?