Last active
September 15, 2020 11:49
-
-
Save kumajaya/cf485afea01708f999fdabad1196d4ca to your computer and use it in GitHub Desktop.
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": "5e6a69ab.9287a8", | |
"type": "modbus-flex-getter", | |
"z": "5292141d.df2d7c", | |
"name": "Moxa Read", | |
"showStatusActivities": false, | |
"showErrors": true, | |
"logIOActivities": false, | |
"server": "f2f5762f.4325a8", | |
"useIOFile": false, | |
"ioFile": "", | |
"useIOForPayload": false, | |
"emptyMsgOnFail": false, | |
"keepMsgProperties": false, | |
"x": 550, | |
"y": 80, | |
"wires": [ | |
[ | |
"5416a4c2.62102c" | |
], | |
[] | |
] | |
}, | |
{ | |
"id": "ebc0b13.9e04a5", | |
"type": "inject", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"props": [ | |
{ | |
"p": "payload" | |
}, | |
{ | |
"p": "topic", | |
"vt": "str" | |
} | |
], | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"onceDelay": 0.1, | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"x": 100, | |
"y": 80, | |
"wires": [ | |
[ | |
"3a71a6d6.15665a" | |
] | |
] | |
}, | |
{ | |
"id": "3a71a6d6.15665a", | |
"type": "function", | |
"z": "5292141d.df2d7c", | |
"name": "AI Scaling", | |
"func": "let out = [];\nlet tmp;\n\ntmp = { topic:'moxa/e1242-00/ai-00/float', payload:{ 'fc': 4, 'unitid': 1, 'address': 520, 'quantity': 2 } };\nout.push(tmp);\ntmp = { topic:'moxa/e1242-00/ai-01/float', payload:{ 'fc': 4, 'unitid': 1, 'address': 522, 'quantity': 2 } };\nout.push(tmp);\ntmp = { topic:'moxa/e1242-00/ai-02/float', payload:{ 'fc': 4, 'unitid': 1, 'address': 524, 'quantity': 2 } };\nout.push(tmp);\ntmp = { topic:'moxa/e1242-00/ai-03/float', payload:{ 'fc': 4, 'unitid': 1, 'address': 526, 'quantity': 2 } };\nout.push(tmp);\n\nreturn [out];", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"x": 360, | |
"y": 80, | |
"wires": [ | |
[ | |
"5e6a69ab.9287a8" | |
] | |
] | |
}, | |
{ | |
"id": "5416a4c2.62102c", | |
"type": "function", | |
"z": "5292141d.df2d7c", | |
"name": "parse", | |
"func": "function scale(valueIn, baseMin, baseMax, limitMin, limitMax) {\n return ((limitMax - limitMin) * (valueIn - baseMin) / (baseMax - baseMin)) + limitMin;\n}\n\nlet val = msg.payload; // 4 bytes, 2301 format for float\nconst buf = Buffer.allocUnsafe(4);\n\nif (msg.topic.includes('float')) {\n buf.writeUInt16BE(val[1]);\n msg.payload = parseFloat(buf.readFloatBE(0).toFixed(3));\n} else {\n msg.payload = parseFloat(scale(msg.payload, 0, 65535, 4.0, 20.0).toFixed(3));\n}\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"x": 730, | |
"y": 80, | |
"wires": [ | |
[ | |
"42535259.267b7c", | |
"4b7329cd.186a38" | |
] | |
] | |
}, | |
{ | |
"id": "42535259.267b7c", | |
"type": "debug", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"active": false, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "payload", | |
"targetType": "msg", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 930, | |
"y": 80, | |
"wires": [] | |
}, | |
{ | |
"id": "4b7329cd.186a38", | |
"type": "mqtt out", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"topic": "", | |
"qos": "0", | |
"retain": "false", | |
"broker": "186c13ea.75e17c", | |
"x": 910, | |
"y": 120, | |
"wires": [] | |
}, | |
{ | |
"id": "bd60f69d.06d078", | |
"type": "mqtt in", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"topic": "moxa/e1242-00/+/+", | |
"qos": "0", | |
"datatype": "auto", | |
"broker": "186c13ea.75e17c", | |
"x": 710, | |
"y": 160, | |
"wires": [ | |
[ | |
"64961125.a6d49" | |
] | |
] | |
}, | |
{ | |
"id": "64961125.a6d49", | |
"type": "debug", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "false", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 930, | |
"y": 160, | |
"wires": [] | |
}, | |
{ | |
"id": "a261a36e.a255c", | |
"type": "function", | |
"z": "5292141d.df2d7c", | |
"name": "AI", | |
"func": "let out = [];\nlet tmp;\n\ntmp = { topic:'moxa/e1242-00/ai-00/raw', payload:{ 'fc': 4, 'unitid': 1, 'address': 512, 'quantity': 1 } };\nout.push(tmp);\ntmp = { topic:'moxa/e1242-00/ai-01/raw', payload:{ 'fc': 4, 'unitid': 1, 'address': 513, 'quantity': 1 } };\nout.push(tmp);\ntmp = { topic:'moxa/e1242-00/ai-02/raw', payload:{ 'fc': 4, 'unitid': 1, 'address': 514, 'quantity': 1 } };\nout.push(tmp);\ntmp = { topic:'moxa/e1242-00/ai-03/raw', payload:{ 'fc': 4, 'unitid': 1, 'address': 515, 'quantity': 1 } };\nout.push(tmp);\n\nreturn [out];", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"x": 350, | |
"y": 40, | |
"wires": [ | |
[ | |
"5e6a69ab.9287a8" | |
] | |
] | |
}, | |
{ | |
"id": "5775b406.8e2dcc", | |
"type": "inject", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"props": [ | |
{ | |
"p": "payload" | |
}, | |
{ | |
"p": "topic", | |
"vt": "str" | |
} | |
], | |
"repeat": "300", | |
"crontab": "", | |
"once": false, | |
"onceDelay": 0.1, | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"x": 110, | |
"y": 40, | |
"wires": [ | |
[ | |
"a261a36e.a255c" | |
] | |
] | |
}, | |
{ | |
"id": "b9daf73b.e5c7d8", | |
"type": "catch", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"scope": [ | |
"5e6a69ab.9287a8" | |
], | |
"uncaught": false, | |
"x": 70, | |
"y": 160, | |
"wires": [ | |
[ | |
"665aa8c7.6ef368" | |
] | |
] | |
}, | |
{ | |
"id": "665aa8c7.6ef368", | |
"type": "delay", | |
"z": "5292141d.df2d7c", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "10", | |
"timeoutUnits": "seconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 220, | |
"y": 160, | |
"wires": [ | |
[ | |
"a261a36e.a255c" | |
] | |
] | |
}, | |
{ | |
"id": "f2f5762f.4325a8", | |
"type": "modbus-client", | |
"z": "", | |
"name": "Moxa E1242-00", | |
"clienttype": "tcp", | |
"bufferCommands": true, | |
"stateLogEnabled": false, | |
"queueLogEnabled": false, | |
"tcpHost": "192.168.4.243", | |
"tcpPort": "502", | |
"tcpType": "DEFAULT", | |
"serialPort": "/dev/ttyUSB", | |
"serialType": "RTU-BUFFERD", | |
"serialBaudrate": "9600", | |
"serialDatabits": "8", | |
"serialStopbits": "1", | |
"serialParity": "none", | |
"serialConnectionDelay": "100", | |
"unit_id": "1", | |
"commandDelay": "1", | |
"clientTimeout": "1000", | |
"reconnectOnTimeout": true, | |
"reconnectTimeout": "2000", | |
"parallelUnitIdsAllowed": true | |
}, | |
{ | |
"id": "186c13ea.75e17c", | |
"type": "mqtt-broker", | |
"z": "", | |
"name": "Mosquitto", | |
"broker": "localhost", | |
"port": "1883", | |
"clientid": "", | |
"usetls": false, | |
"compatmode": false, | |
"keepalive": "60", | |
"cleansession": true, | |
"birthTopic": "", | |
"birthQos": "0", | |
"birthPayload": "", | |
"closeTopic": "", | |
"closeQos": "0", | |
"closePayload": "", | |
"willTopic": "", | |
"willQos": "0", | |
"willPayload": "" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment