node-red发送TCP消息
2023-08-01 本文已影响0人
wwmin_
使用node-red搭建TCP服务及客户端发送消息
node-red发送TCP消息效果
node-red发送TCP数据
使用网络调试助手效果
网络调试助手效果
导出的JSON数据
[
{
"id": "052a3db92a575e25",
"type": "tab",
"label": "Flow 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "8e616c43d615a499",
"type": "tcp in",
"z": "052a3db92a575e25",
"name": "TCP服务端9529",
"server": "server",
"host": "localhost",
"port": "9529",
"datamode": "stream",
"datatype": "utf8",
"newline": "\\n",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 140,
"y": 300,
"wires": [
[
"d6dbac1ff703953e",
"fe7fb59413d0c8d3"
]
]
},
{
"id": "d6dbac1ff703953e",
"type": "debug",
"z": "052a3db92a575e25",
"name": "TCP Debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 370,
"y": 420,
"wires": []
},
{
"id": "fe7fb59413d0c8d3",
"type": "switch",
"z": "052a3db92a575e25",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "temp",
"vt": "str"
},
{
"t": "eq",
"v": "data",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 370,
"y": 300,
"wires": [
[
"eb8dc88a5367d8e1"
],
[
"7b4d092fde8a33b6"
],
[
"e661d60bc5a48a79"
]
]
},
{
"id": "eb8dc88a5367d8e1",
"type": "change",
"z": "052a3db92a575e25",
"name": "输出: 20",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "20",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 580,
"y": 240,
"wires": [
[
"76b22d684558ecbc"
]
]
},
{
"id": "7b4d092fde8a33b6",
"type": "change",
"z": "052a3db92a575e25",
"name": "输出: 70",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "70",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 580,
"y": 300,
"wires": [
[
"76b22d684558ecbc"
]
]
},
{
"id": "7b36f8692e361e47",
"type": "inject",
"z": "052a3db92a575e25",
"name": "Hello from server.",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "hello from server",
"payloadType": "str",
"x": 620,
"y": 140,
"wires": [
[
"76b22d684558ecbc"
]
]
},
{
"id": "76b22d684558ecbc",
"type": "template",
"z": "052a3db92a575e25",
"name": "+换行",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{payload}}\n",
"output": "str",
"x": 790,
"y": 300,
"wires": [
[
"f4dac0efb0b08172"
]
]
},
{
"id": "f4dac0efb0b08172",
"type": "tcp out",
"z": "052a3db92a575e25",
"name": "tcp out 发送消息",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"tls": "",
"x": 920,
"y": 440,
"wires": []
},
{
"id": "5f6db86b760f1214",
"type": "tcp in",
"z": "052a3db92a575e25",
"name": "TCP客户端9529",
"server": "client",
"host": "192.168.1.199",
"port": "9529",
"datamode": "stream",
"datatype": "utf8",
"newline": "\\n",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 140,
"y": 680,
"wires": [
[
"8aa5057c5a1b94d3",
"e9085a0028eae0b9"
]
]
},
{
"id": "8aa5057c5a1b94d3",
"type": "function",
"z": "052a3db92a575e25",
"name": "no msg back",
"func": "",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 680,
"wires": [
[
"102aaed59134cec0"
]
],
"info": "function节点,目的是中断流程,避免之后的tcp out节点再输出msg.payload属性值,删除function节点的return msg代码"
},
{
"id": "e9085a0028eae0b9",
"type": "debug",
"z": "052a3db92a575e25",
"name": "tcp client debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 380,
"y": 780,
"wires": []
},
{
"id": "c28089f19d018321",
"type": "inject",
"z": "052a3db92a575e25",
"name": "temp",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "temp",
"payloadType": "str",
"x": 350,
"y": 540,
"wires": [
[
"98192e1e49f10eb3"
]
]
},
{
"id": "fb4f2014162aa801",
"type": "inject",
"z": "052a3db92a575e25",
"name": "data",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "data",
"payloadType": "str",
"x": 350,
"y": 600,
"wires": [
[
"98192e1e49f10eb3"
]
]
},
{
"id": "98192e1e49f10eb3",
"type": "template",
"z": "052a3db92a575e25",
"name": "+ 换行",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{payload}}\n",
"output": "str",
"x": 550,
"y": 580,
"wires": [
[
"102aaed59134cec0"
]
]
},
{
"id": "102aaed59134cec0",
"type": "tcp out",
"z": "052a3db92a575e25",
"name": "tcp out: 送出信息",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"tls": "",
"x": 830,
"y": 680,
"wires": []
},
{
"id": "e661d60bc5a48a79",
"type": "change",
"z": "052a3db92a575e25",
"name": "一般消息",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 580,
"y": 380,
"wires": [
[
"f4dac0efb0b08172"
]
]
}
]