You are using the [repeat] function of [inject] to receive data every 15 minutes from the [modbus-flex-sequencer node].
You should receive data from a total of 10 devices through modbus. When you first deploy and run Nordred, the data for 10 devices is transmitted well. However, in the second iteration, only data for device 1 is transmitted. Do you know why this is the case?
Here is my nodered code.
[
{
"id": "4e7bc0d34e695226",
"type": "crontinject",
"z": "53c7c787661b774e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "900",
"crontab": "",
"once": true,
"onceDelay": "2.1",
"topic": "",
"payload": "",
"payloadType": "date",
"crontiMethod": "",
"crontiArgs": "[]",
"inputs": 0,
"hasButton": true,
"x": 250,
"y": 280,
"wires": [
[
"498e5f3556ef1628"
]
]
},
{
"id": "498e5f3556ef1628",
"type": "modbus-flex-sequencer",
"z": "53c7c787661b774e",
"name": "",
"sequences": [
{
"name": "1",
"unitid": "1",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "2",
"unitid": "2",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "3",
"unitid": "3",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "4",
"unitid": "4",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "5",
"unitid": "5",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "6",
"unitid": "6",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "7",
"unitid": "7",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "8",
"unitid": "8",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "9",
"unitid": "9",
"fc": "FC4",
"address": "0",
"quantity": "44"
},
{
"name": "10",
"unitid": "10",
"fc": "FC4",
"address": "0",
"quantity": "44"
}
],
"server": "fd93d7ae22777e95",
"showStatusActivities": false,
"showErrors": false,
"showWarnings": true,
"logIOActivities": false,
"useIOFile": false,
"ioFile": "",
"useIOForPayload": false,
"emptyMsgOnFail": false,
"keepMsgProperties": true,
"delayOnStart": false,
"startDelayTime": "100",
"x": 540,
"y": 280,
"wires": [
[
"13b3612ca129149e",
"09bc7395f5bb11d3",
"5708a8886f25e57c"
],
[]
],
"info": "Server 세팅에서 Timeout(ms)이 1000으로 설정시 전력량계 통신이 5~6개 통신시 timeout 에러 발생\r\nTimeout(ms)를 2000으로 세텡하고 시험시 현재 10대 까지 timeout 에러 없슴\r\n"
},
{
"id": "13b3612ca129149e",
"type": "function",
"z": "53c7c787661b774e",
"name": "modbus노드에 따른 site등록",
"func": "var siteID = 1;\nvar siteName = \"더콘솔\";\nvar query = \"SELECT * FROM tb_site WHERE SITE_CODE='\" + siteID + \"' AND SITE_NAME='\" + siteName + \"';\";\nmsg.topic = query;\nmsg.siteID = siteID;\nmsg.siteName = siteName;\nflow.set(\"siteID\",siteID);\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 900,
"y": 240,
"wires": [
[
"91d483450409bd58"
]
]
},
{
"id": "91d483450409bd58",
"type": "mysql",
"z": "53c7c787661b774e",
"mydb": "20fc62db2276ec96",
"name": "",
"x": 1065,
"y": 240,
"wires": [
[
"faac45c8d62764be"
]
],
"l": false
},
{
"id": "faac45c8d62764be",
"type": "function",
"z": "53c7c787661b774e",
"name": "분기",
"func": "if (msg.payload.length === 0) {\n msg.siteExists = false;\n} else {\n msg.siteExists = true;\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1170,
"y": 240,
"wires": [
[
"d15068fdeca717e6"
]
]
},
{
"id": "d15068fdeca717e6",
"type": "switch",
"z": "53c7c787661b774e",
"name": "",
"property": "siteExists",
"propertyType": "msg",
"rules": [
{
"t": "false"
},
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1330,
"y": 240,
"wires": [
[
"3351491a86e42bec"
],
[
"cc0e75ac470adc02"
]
]
},
{
"id": "3351491a86e42bec",
"type": "function",
"z": "53c7c787661b774e",
"name": "site 자동등록",
"func": "var siteID = flow.get(\"siteID\");\nvar siteName = flow.get(\"siteName\");\n\nvar query = \"INSERT INTO tb_site (SITE_CODE,SITE_NAME) values (?,?);\";\nmsg.topic= query;\nmsg.payload = [siteID,siteName];\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1630,
"y": 220,
"wires": [
[]
]
},
{
"id": "cc0e75ac470adc02",
"type": "function",
"z": "53c7c787661b774e",
"name": "저장된 Device 자동등록",
"func": "var deviceID = msg.unitid;\nvar siteID = msg.siteID;\n\nvar query = \"INSERT INTO tb_mtr_info (SITE_CODE, MTR_NO) VALUES (?, ?) ON DUPLICATE KEY UPDATE MTR_NO = MTR_NO;\";\nmsg.topic = query;\nmsg.payload = [siteID, deviceID];\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1670,
"y": 260,
"wires": [
[
"be3aa5432905b4a2"
]
]
},
{
"id": "be3aa5432905b4a2",
"type": "mysql",
"z": "53c7c787661b774e",
"mydb": "20fc62db2276ec96",
"name": "",
"x": 1815,
"y": 260,
"wires": [
[]
],
"l": false
},
{
"id": "8f37c0dccbfb0682",
"type": "mysql",
"z": "53c7c787661b774e",
"mydb": "20fc62db2276ec96",
"name": "",
"x": 1175,
"y": 300,
"wires": [
[
"26578295ec04d73d"
]
],
"l": false
},
{
"id": "cf301ffcf9c41f96",
"type": "function",
"z": "53c7c787661b774e",
"name": "function 14",
"func": "var date = new Date();\nvar month = date.getMonth() + 1;\nvar day = date.getDate();\n\nif (day == 1) {\n var realday = \"Mon\";\n} else if (day == 2) {\n realday = \"Tue\";\n} else if (day == 3) {\n realday = \"Wed\";\n} else if (day == 4) {\n realday = \"Thur\";\n} else if (day == 5) {\n realday = \"Fri\";\n} else if (day == 6) {\n realday = \"Sat\";\n} else if (day == 0) {\n realday = \"Sun\";\n}\n\n// 날짜, 시간 값을 두 자리수로 표현하도록 수정합니다.\nvar format_date = date.getFullYear() + \"-\" + (\"0\" + month).slice(-2) + \"-\" + (\"0\" + date.getDate()).slice(-2) + \" \" +\n (\"0\" + date.getHours()).slice(-2) + \":\" + (\"0\" + date.getMinutes()).slice(-2) + \":\" +\n (\"0\" + date.getSeconds()).slice(-2);\n\nvar siteID = flow.get(\"siteID\");\n\n// 반복문으로 데이터베이스에 저장\n var deviceID = msg.payload.DevID;\n var Active_PowerEnergy = msg.payload.Active_PowerEnergy;\n var Reactive_PowerEnergy = msg.payload.Reactive_PowerEnergy;\n var A_Phase_Voltage = msg.payload.A_Phase_Voltage;\n var B_Phase_Voltage = msg.payload.B_Phase_Voltage;\n var C_Phase_Voltage = msg.payload.C_Phase_Voltage;\n var A_Phase_Current = msg.payload.A_Phase_Current;\n var B_Phase_Current = msg.payload.B_Phase_Current;\n var C_Phase_Current = msg.payload.C_Phase_Current;\n var A_Phase_Angle = msg.payload.A_Phase_Angle;\n var B_Phase_Angle = msg.payload.B_Phase_Angle;\n var C_Phase_Angle = msg.payload.C_Phase_Angle;\n var A_Phase_PF = msg.payload.A_Phase_PF;\n var B_Phase_PF = msg.payload.B_Phase_PF;\n var C_Phase_PF = msg.payload.C_Phase_PF;\n var Total_Active_Power = msg.payload.Total_Active_Power;\n var Total_Reactive_Power = msg.payload.Total_Reactive_Power;\n var A_Active_Power = msg.payload.A_Active_Power;\n var B_Active_Power = msg.payload.B_Active_Power;\n var C_Active_Power = msg.payload.C_Active_Power;\n var A_Reactive_Power = msg.payload.A_Reactive_Power;\n var B_Reactive_Power = msg.payload.B_Reactive_Power;\n var C_Reactive_Power = msg.payload.C_Reactive_Power;\n\n var query = \"INSERT INTO tb_curr_data (SITE_CODE,MTR_NO,READ_DT,F_CUM_ACT_E,F_CUM_REACT_E,VOLTAGE_A,VOLTAGE_B,VOLTAGE_C,CURRENT_A,CURRENT_B,CURRENT_C,PHI_A,PHI_B,PHI_C,PF_A,PF_B,PF_C,ACT_PWR_T,REACT_PWR_T,ACT_PWR_A,ACT_PWR_B,ACT_PWR_C,REACT_PWR_A,REACT_PWR_B,REACT_PWR_C) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);\";\n msg.topic = query;\n msg.payload = [siteID, deviceID, format_date, Active_PowerEnergy, Reactive_PowerEnergy, A_Phase_Voltage, B_Phase_Voltage, C_Phase_Voltage, A_Phase_Current, B_Phase_Current, C_Phase_Current, A_Phase_Angle, B_Phase_Angle, C_Phase_Angle, A_Phase_PF, B_Phase_PF, C_Phase_PF, Total_Active_Power, Total_Reactive_Power, A_Active_Power, B_Active_Power, C_Active_Power, A_Reactive_Power, B_Reactive_Power, C_Reactive_Power];\n\n // MySQL 노드로 메시지 전송\n return msg;\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1050,
"y": 300,
"wires": [
[
"8f37c0dccbfb0682",
"060e7c4d2e72117c"
]
]
},
{
"id": "5708a8886f25e57c",
"type": "function",
"z": "53c7c787661b774e",
"name": "Save To DB",
"func": "var values = msg.payload;\nvar combinedValues = [];\nvar floatValues = [];\n\nfor (var i = 0; i < values.length; i += 44) {\n var devid = msg.unitid;\n var devValues = values.slice(i, i + 44);\n combinedValues = [];\n floatValues = [];\n\n for (var j = 0; j < 22; j++) {\n if (j < 2) {\n combinedValues[j] = (devValues[j * 2 + 1] << 16) + devValues[j * 2];\n floatValues[j] = combinedValues[j];\n } else {\n combinedValues[j] = (devValues[j * 2 + 1] << 16) + devValues[j * 2];\n\n var buffer = new ArrayBuffer(4);\n var intView = new Int32Array(buffer);\n var floatView = new Float32Array(buffer);\n\n intView[0] = combinedValues[j];\n floatValues[j] = floatView[0];\n }\n }\n\n // 데이터베이스에 저장하기 위해 msg.payload 생성\n msg.payload = {\n DevID: devid,\n Active_PowerEnergy: floatValues[0].toFixed(4),\n Reactive_PowerEnergy: floatValues[1].toFixed(4),\n A_Phase_Voltage: floatValues[2].toFixed(4),\n B_Phase_Voltage: floatValues[3].toFixed(4),\n C_Phase_Voltage: floatValues[4].toFixed(4),\n A_Phase_Current: floatValues[5].toFixed(4),\n B_Phase_Current: floatValues[6].toFixed(4),\n C_Phase_Current: floatValues[7].toFixed(4),\n A_Phase_Angle: floatValues[8].toFixed(4),\n B_Phase_Angle: floatValues[9].toFixed(4),\n C_Phase_Angle: floatValues[10].toFixed(4),\n A_Phase_PF: floatValues[11].toFixed(4),\n B_Phase_PF: floatValues[12].toFixed(4),\n C_Phase_PF: floatValues[13].toFixed(4),\n Total_Active_Power: floatValues[14].toFixed(4),\n Total_Reactive_Power: floatValues[15].toFixed(4),\n A_Active_Power: floatValues[16].toFixed(4),\n B_Active_Power: floatValues[17].toFixed(4),\n C_Active_Power: floatValues[18].toFixed(4),\n A_Reactive_Power: floatValues[19].toFixed(4),\n B_Reactive_Power: floatValues[20].toFixed(4),\n C_Reactive_Power: floatValues[21].toFixed(4)\n };\n\n // 데이터베이스에 저장하는 코드 추가\n // ...\n}\n\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 810,
"y": 300,
"wires": [
[
"cf301ffcf9c41f96",
"c9559f5757bc6e33"
]
]
},
{
"id": "09bc7395f5bb11d3",
"type": "debug",
"z": "53c7c787661b774e",
"name": "debug 169",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 730,
"y": 360,
"wires": []
},
{
"id": "fd93d7ae22777e95",
"type": "modbus-client",
"name": "",
"clienttype": "tcp",
"bufferCommands": true,
"stateLogEnabled": false,
"queueLogEnabled": false,
"failureLogEnabled": true,
"tcpHost": "192.168.0.109",
"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": "2000",
"reconnectOnTimeout": false,
"reconnectTimeout": "2000",
"parallelUnitIdsAllowed": true,
"showErrors": false,
"showWarnings": true,
"showLogs": true
},
{
"id": "20fc62db2276ec96",
"type": "MySQLdatabase",
"name": "",
"host": "127.0.0.1",
"port": "3306",
"db": "ndbm",
"tz": "",
"charset": "UTF8"
}
]