Created
July 25, 2022 19:05
-
-
Save blip2/de1ed906ad8323d886c727986d6b1653 to your computer and use it in GitHub Desktop.
Node red export to poll a deep-sea generator using modbus TCP and push data out to MQTT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "f6f2187d.f17ca8", | |
"type": "tab", | |
"label": "Generator Modbus", | |
"disabled": false, | |
"info": "" | |
}, | |
{ | |
"id": "d48f79b6327932c7", | |
"type": "modbus-flex-getter", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-p", | |
"showStatusActivities": true, | |
"showErrors": true, | |
"logIOActivities": false, | |
"server": "7cfcfcaad501b340", | |
"useIOFile": false, | |
"ioFile": "", | |
"useIOForPayload": false, | |
"emptyMsgOnFail": false, | |
"keepMsgProperties": true, | |
"x": 490, | |
"y": 60, | |
"wires": [ | |
[ | |
"f5b326dd071fe090" | |
], | |
[] | |
] | |
}, | |
{ | |
"id": "d65782abdbd3604f", | |
"type": "function", | |
"z": "f6f2187d.f17ca8", | |
"name": "registers", | |
"func": "registers = [\n // basic instrucmentation\n {\"payload\": { 'fc': 3, 'unitid': 1, 'address': 1024 , 'quantity': 34 },},\n // fuel\n {\"payload\": { 'fc': 3, 'unitid': 1, 'address': 1290 , 'quantity': 2 },},\n // derived values\n {\"payload\": { 'fc': 3, 'unitid': 1, 'address': 1536 , 'quantity': 34 },},\n];\nreturn Array.from({length: node.outputCount}, () => registers);", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 260, | |
"y": 140, | |
"wires": [ | |
[ | |
"d48f79b6327932c7", | |
"b440ef4f381a4c81", | |
"a826f73c6ed834d9", | |
"b32a06952727d7f8" | |
] | |
] | |
}, | |
{ | |
"id": "4fb9ff35b518f775", | |
"type": "inject", | |
"z": "f6f2187d.f17ca8", | |
"name": "poll", | |
"props": [ | |
{ | |
"p": "payload" | |
} | |
], | |
"repeat": "20", | |
"crontab": "", | |
"once": true, | |
"onceDelay": "1", | |
"topic": "", | |
"payload": "true", | |
"payloadType": "bool", | |
"x": 110, | |
"y": 140, | |
"wires": [ | |
[ | |
"d65782abdbd3604f" | |
] | |
] | |
}, | |
{ | |
"id": "c9dcaed7f662a0db", | |
"type": "function", | |
"z": "f6f2187d.f17ca8", | |
"name": "map output", | |
"func": "var data = {}\nif (msg.modbusRequest.address == \"1024\") {\n data = {\n \"oil_pressure\": msg.payload[0],\n \"coolant_temperature\": msg.payload[1],\n \"internal_fuel_level\": msg.payload[3],\n \"battery_voltage\": msg.payload[5]/10,\n \"engine_speed\": msg.payload[6],\n \"frequency\": msg.payload[7]/10,\n \"l1_voltage\": msg.payload[9]/10,\n \"l2_voltage\": msg.payload[11]/10,\n \"l3_voltage\": msg.payload[13]/10,\n \"l1_current\": msg.payload[21]/10,\n \"l2_current\": msg.payload[23]/10,\n \"l3_current\": msg.payload[25]/10,\n \"earth_current\": msg.payload[27]/10,\n \"l1_power\": msg.payload[29],\n \"l2_power\": msg.payload[31],\n \"l3_power\": msg.payload[33],\n };\n} else if (msg.modbusRequest.address == \"1290\") {\n if (msg.payload[1] != \"65535\") {\n data = {\n \"fuel_consumption\": msg.payload[1]/100,\n }\n }\n} else if (msg.modbusRequest.address == \"1536\") {\n data = {\n \"true_power\": msg.payload[1],\n \"l1_apparent_power\": msg.payload[3],\n \"l2_apparent_power\": msg.payload[5],\n \"l3_apparent_power\": msg.payload[7],\n \"apparent_power\": msg.payload[9],\n \"l1_reactive_power\": msg.payload[11],\n \"l2_reactice_power\": msg.payload[13],\n \"l3_reactive_power\": msg.payload[15],\n \"reactive_power\": msg.payload[17],\n \"power_factor\": msg.payload[21]/100,\n };\n}\nvar payload = Object.keys(data).map((key) => { return {\"topic\": \"emf/power/\" + msg.topic + \"/\" + key, \"payload\": data[key]}});\nreturn [payload,];", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 850, | |
"y": 140, | |
"wires": [ | |
[ | |
"1e519cd17fcb7670" | |
] | |
] | |
}, | |
{ | |
"id": "f5b326dd071fe090", | |
"type": "function", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-p", | |
"func": "msg.topic = \"generator-p\";\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 650, | |
"y": 60, | |
"wires": [ | |
[ | |
"c9dcaed7f662a0db" | |
] | |
] | |
}, | |
{ | |
"id": "b440ef4f381a4c81", | |
"type": "modbus-flex-getter", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-q", | |
"showStatusActivities": true, | |
"showErrors": true, | |
"logIOActivities": false, | |
"server": "a9a861f61b94e425", | |
"useIOFile": false, | |
"ioFile": "", | |
"useIOForPayload": false, | |
"emptyMsgOnFail": false, | |
"keepMsgProperties": true, | |
"x": 490, | |
"y": 120, | |
"wires": [ | |
[ | |
"edc0a22b9bfd6152" | |
], | |
[] | |
] | |
}, | |
{ | |
"id": "edc0a22b9bfd6152", | |
"type": "function", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-q", | |
"func": "msg.topic = \"generator-q\";\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 650, | |
"y": 120, | |
"wires": [ | |
[ | |
"c9dcaed7f662a0db" | |
] | |
] | |
}, | |
{ | |
"id": "a826f73c6ed834d9", | |
"type": "modbus-flex-getter", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-r", | |
"showStatusActivities": true, | |
"showErrors": true, | |
"logIOActivities": false, | |
"server": "499c574bc63c9dbf", | |
"useIOFile": false, | |
"ioFile": "", | |
"useIOForPayload": false, | |
"emptyMsgOnFail": false, | |
"keepMsgProperties": true, | |
"x": 490, | |
"y": 180, | |
"wires": [ | |
[ | |
"141f845856e208e0" | |
], | |
[] | |
] | |
}, | |
{ | |
"id": "141f845856e208e0", | |
"type": "function", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-r", | |
"func": "msg.topic = \"generator-r\";\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 650, | |
"y": 180, | |
"wires": [ | |
[ | |
"c9dcaed7f662a0db" | |
] | |
] | |
}, | |
{ | |
"id": "b32a06952727d7f8", | |
"type": "modbus-flex-getter", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-s", | |
"showStatusActivities": true, | |
"showErrors": true, | |
"logIOActivities": false, | |
"server": "061f619068ad7792", | |
"useIOFile": false, | |
"ioFile": "", | |
"useIOForPayload": false, | |
"emptyMsgOnFail": false, | |
"keepMsgProperties": true, | |
"x": 490, | |
"y": 240, | |
"wires": [ | |
[ | |
"e114f16a51b372d3" | |
], | |
[] | |
] | |
}, | |
{ | |
"id": "e114f16a51b372d3", | |
"type": "function", | |
"z": "f6f2187d.f17ca8", | |
"name": "generator-s", | |
"func": "msg.topic = \"generator-s\";\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 650, | |
"y": 240, | |
"wires": [ | |
[ | |
"c9dcaed7f662a0db" | |
] | |
] | |
}, | |
{ | |
"id": "1e519cd17fcb7670", | |
"type": "mqtt out", | |
"z": "f6f2187d.f17ca8", | |
"name": "MQTT", | |
"topic": "", | |
"qos": "1", | |
"retain": "", | |
"respTopic": "", | |
"contentType": "", | |
"userProps": "", | |
"correl": "", | |
"expiry": "", | |
"broker": "0d46b03dc65ea258", | |
"x": 1030, | |
"y": 140, | |
"wires": [] | |
}, | |
{ | |
"id": "7cfcfcaad501b340", | |
"type": "modbus-client", | |
"name": "generator-p", | |
"clienttype": "tcp", | |
"bufferCommands": true, | |
"stateLogEnabled": false, | |
"queueLogEnabled": false, | |
"tcpHost": "172.20.24.52", | |
"tcpPort": "502", | |
"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": "a9a861f61b94e425", | |
"type": "modbus-client", | |
"name": "generator-q", | |
"clienttype": "tcp", | |
"bufferCommands": true, | |
"stateLogEnabled": false, | |
"queueLogEnabled": false, | |
"tcpHost": "172.20.24.10", | |
"tcpPort": "502", | |
"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": "499c574bc63c9dbf", | |
"type": "modbus-client", | |
"name": "generator-r", | |
"clienttype": "tcp", | |
"bufferCommands": true, | |
"stateLogEnabled": false, | |
"queueLogEnabled": false, | |
"tcpHost": "172.20.24.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": "1", | |
"commandDelay": "1", | |
"clientTimeout": "1000", | |
"reconnectOnTimeout": true, | |
"reconnectTimeout": "2000", | |
"parallelUnitIdsAllowed": true | |
}, | |
{ | |
"id": "061f619068ad7792", | |
"type": "modbus-client", | |
"name": "generator-s", | |
"clienttype": "tcp", | |
"bufferCommands": true, | |
"stateLogEnabled": false, | |
"queueLogEnabled": false, | |
"tcpHost": "172.20.24.12", | |
"tcpPort": "502", | |
"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": "0d46b03dc65ea258", | |
"type": "mqtt-broker", | |
"name": "mqtt.emf.camp", | |
"broker": "mqtt.emf.camp", | |
"port": "1883", | |
"clientid": "generator-node-red", | |
"autoConnect": true, | |
"usetls": false, | |
"protocolVersion": "4", | |
"keepalive": "60", | |
"cleansession": true, | |
"birthTopic": "", | |
"birthQos": "0", | |
"birthPayload": "", | |
"birthMsg": {}, | |
"closeTopic": "", | |
"closeQos": "0", | |
"closePayload": "", | |
"closeMsg": {}, | |
"willTopic": "", | |
"willQos": "0", | |
"willPayload": "", | |
"willMsg": {}, | |
"sessionExpiry": "" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment