1. 电表读取数据

导出node-red节点
[
{
"id": "95dc0dd050ab3901",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "baadb31eff879fb1",
"type": "inject",
"z": "95dc0dd050ab3901",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 120,
"y": 120,
"wires": [
[
"ea4c7e63204009d0"
]
]
},
{
"id": "799a16756d7dc6d8",
"type": "debug",
"z": "95dc0dd050ab3901",
"name": "debug 13",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1160,
"y": 400,
"wires": []
},
{
"id": "52c0fe628651a67b",
"type": "serial port",
"z": "95dc0dd050ab3901",
"name": "",
"serial": "87f78da6b6ce12e3",
"x": 580,
"y": 400,
"wires": [
[
"d734a3d4055b7ca4"
]
]
},
{
"id": "ea43aaa56da4c5fd",
"type": "debug",
"z": "95dc0dd050ab3901",
"name": "调试 7",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 120,
"wires": []
},
{
"id": "d734a3d4055b7ca4",
"type": "function",
"z": "95dc0dd050ab3901",
"name": "解析成json",
"func": "var target = {\n \"id\": \"1102363\",\n \"com\": {\n \"port\": \"1\",\n \"baud\": \"2400\",\n \"parity\": \"2\"\n },\n \"data\": {\n \"type\": \"1\",\n \"sch_no\": \"\",\n \"frame\": \"01 06 00 00 00 00 89 CA\"\n }\n}\nlet buffer = msg.payload;\nlet frame = JSON.parse(JSON.stringify(buffer)).data.map(p => p.toString(16).padStart(2,\"0\")).join(\" \");\ntarget.data.frame = frame;\nmsg.payload = target;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 400,
"wires": [
[
"b65a484ed40e9aef"
]
]
},
{
"id": "b65a484ed40e9aef",
"type": "function",
"z": "95dc0dd050ab3901",
"name": "序列化成Buffer",
"func": "msg.payload = Buffer.from(JSON.stringify(msg.payload));\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 980,
"y": 400,
"wires": [
[
"799a16756d7dc6d8",
"0b58ebdacc5d2f31"
]
]
},
{
"id": "2eef359efd2e5fbb",
"type": "tcp in",
"z": "95dc0dd050ab3901",
"name": "TCP服务端9529",
"server": "server",
"host": "",
"port": "9529",
"datamode": "stream",
"datatype": "buffer",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 120,
"y": 520,
"wires": [
[
"e815fcba1ef09e26",
"a3c883d6c689f907",
"d233df8f941cf211"
]
]
},
{
"id": "0b58ebdacc5d2f31",
"type": "tcp out",
"z": "95dc0dd050ab3901",
"name": "",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"tls": "",
"x": 1150,
"y": 520,
"wires": []
},
{
"id": "e815fcba1ef09e26",
"type": "function",
"z": "95dc0dd050ab3901",
"name": "仅回复心跳",
"func": "var payload = msg.payload.toString(\"utf8\");\nif (payload.startsWith('3')) {\n msg.payload = 1;\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 450,
"y": 520,
"wires": [
[
"0b58ebdacc5d2f31"
]
]
},
{
"id": "a3c883d6c689f907",
"type": "function",
"z": "95dc0dd050ab3901",
"name": "645数据序列化命令",
"func": "var payload = msg.payload.toString(\"utf8\");\nif(payload.startsWith('3')){\n return;\n}\nmsg.payload = Buffer.from(JSON.parse(payload).data.frame.trim().split(\" \").map(p=>parseInt(p,16)));\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 400,
"wires": [
[
"52c0fe628651a67b"
]
]
},
{
"id": "ea4c7e63204009d0",
"type": "DLT645Read",
"z": "95dc0dd050ab3901",
"name": "",
"serial": "4a19a59bebbc09ae",
"columns": [
{
"Key": "ZDL",
"Label": "总电量-1102363",
"Address": "320302164358",
"Tdata": "00000000"
},
{
"Key": "L1-ZDL",
"Label": "上1日总电量-1102363",
"Address": "320302164358",
"Tdata": "00000001"
},
{
"Key": "L2-ZDL",
"Label": "上2日总电量-1102363",
"Address": "320302164358",
"Tdata": "00000002"
},
{
"Key": "L3-ZDL",
"Label": "上3日总电流-1102363",
"Address": "320302164358",
"Tdata": "00000003"
},
{
"Key": "A-V",
"Label": "A相电压-1102363",
"Address": "320302164358",
"Tdata": "02010100"
},
{
"Key": "A-I",
"Label": "A相电流-1102363",
"Address": "320302164358",
"Tdata": "02020100"
},
{
"Key": "YGGL",
"Label": "有功功率-1102363",
"Address": "320302164358",
"Tdata": "02030000"
},
{
"Key": "GLYS",
"Label": "功率因数-1102363",
"Address": "320302164358",
"Tdata": "02060000"
}
],
"x": 300,
"y": 120,
"wires": [
[
"ea43aaa56da4c5fd"
]
]
},
{
"id": "d233df8f941cf211",
"type": "debug",
"z": "95dc0dd050ab3901",
"name": "TCP接收到的原始消息",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 360,
"y": 620,
"wires": []
},
{
"id": "87f78da6b6ce12e3",
"type": "serial config",
"name": "串口收发",
"serialport": "/dev/ttyS3",
"baudrate": "9600",
"databits": "8",
"stopbits": "1",
"parity": "none",
"timeout": "50",
"reqtimeout": "1000"
},
{
"id": "4a19a59bebbc09ae",
"type": "serial config",
"name": "温控仪",
"serialport": "/dev/ttyS2",
"baudrate": "9600",
"databits": "8",
"stopbits": "1",
"parity": "none",
"timeout": "50",
"reqtimeout": "5000"
}
]
网友评论