对接TCP协议设备示例
插件图片
功能介绍

通过Node-RED规则引擎的方式接入TCP协议的设备示例

视频讲解:ThingsPanel对接自定义TCP设备【通过规则引擎】_哔哩哔哩_bilibili

JSON代码:

[
  {
    "id": "2428a61e85ba8239",
    "type": "tab",
    "label": "tcp演示"
  },
  {
    "id": "c7d49a890d9772f6",
    "type": "tcp in",
    "z": "2428a61e85ba8239",
    "name": "",
    "server": "server",
    "host": "",
    "port": "9996",
    "datamode": "stream",
    "datatype": "buffer",
    "newline": "",
    "topic": "",
    "trim": false,
    "base64": false,
    "tls": "",
    "x": 280,
    "y": 660,
    "wires": [
      [
        "d422aba0763898df",
        "aca9c9c52839433f",
        "9cc31a9fba7d9631"
      ]
    ]
  },
  {
    "id": "aca9c9c52839433f",
    "type": "debug",
    "z": "2428a61e85ba8239",
    "name": "tcp接收",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 800,
    "y": 660,
    "wires": []
  },
  {
    "id": "d422aba0763898df",
    "type": "tcp out",
    "z": "2428a61e85ba8239",
    "name": "",
    "host": "",
    "port": "",
    "beserver": "reply",
    "base64": false,
    "end": false,
    "tls": "",
    "x": 970,
    "y": 460,
    "wires": []
  },
  {
    "id": "7054df271ffbd8be",
    "type": "inject",
    "z": "2428a61e85ba8239",
    "name": "定时读取15,15-2寄存器",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "[1,3,15,15,0,2,247,28]",
    "payloadType": "bin",
    "x": 360,
    "y": 460,
    "wires": [
      [
        "d422aba0763898df"
      ]
    ]
  },
  {
    "id": "5831cb533a0b6596",
    "type": "tcp request",
    "z": "2428a61e85ba8239",
    "name": "",
    "server": "127.0.0.1",
    "port": "9996",
    "out": "sit",
    "ret": "buffer",
    "splitc": " ",
    "newline": "",
    "trim": false,
    "tls": "",
    "x": 390,
    "y": 260,
    "wires": [
      [
        "933f5f0f5be22441"
      ]
    ]
  },
  {
    "id": "9f9a0bd16d9b8101",
    "type": "inject",
    "z": "2428a61e85ba8239",
    "name": "设备002",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "[0,0,2]",
    "payloadType": "bin",
    "x": 180,
    "y": 260,
    "wires": [
      [
        "5831cb533a0b6596"
      ]
    ]
  },
  {
    "id": "bd4481ac584cc936",
    "type": "tcp request",
    "z": "2428a61e85ba8239",
    "name": "",
    "server": "127.0.0.1",
    "port": "9996",
    "out": "sit",
    "ret": "buffer",
    "splitc": " ",
    "newline": "",
    "trim": false,
    "tls": "",
    "x": 390,
    "y": 180,
    "wires": [
      [
        "680c97843ced4355"
      ]
    ]
  },
  {
    "id": "c1b3017b15769ebc",
    "type": "inject",
    "z": "2428a61e85ba8239",
    "name": "设备001",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "[0,0,1]",
    "payloadType": "bin",
    "x": 180,
    "y": 180,
    "wires": [
      [
        "bd4481ac584cc936"
      ]
    ]
  },
  {
    "id": "239f715a92733841",
    "type": "inject",
    "z": "2428a61e85ba8239",
    "name": "定时读取0,0-2寄存器",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "[1,3,0,0,0,2,196,11]",
    "payloadType": "bin",
    "x": 350,
    "y": 520,
    "wires": [
      [
        "d422aba0763898df"
      ]
    ]
  },
  {
    "id": "933f5f0f5be22441",
    "type": "debug",
    "z": "2428a61e85ba8239",
    "name": "tcp002",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 630,
    "y": 260,
    "wires": []
  },
  {
    "id": "680c97843ced4355",
    "type": "debug",
    "z": "2428a61e85ba8239",
    "name": "tcp001",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 630,
    "y": 180,
    "wires": []
  },
  {
    "id": "e9c745e517061ea1",
    "type": "mqtt out",
    "z": "2428a61e85ba8239",
    "name": "将消息通过mqtt发送到平台",
    "topic": "",
    "qos": "",
    "retain": "",
    "respTopic": "",
    "contentType": "",
    "userProps": "",
    "correl": "",
    "expiry": "",
    "broker": "bf5a2e4e48b2bbdb",
    "x": 740,
    "y": 760,
    "wires": []
  },
  {
    "id": "9cc31a9fba7d9631",
    "type": "function",
    "z": "2428a61e85ba8239",
    "name": "function 2",
    "func": "\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 520,
    "y": 760,
    "wires": [
      [
        "e9c745e517061ea1"
      ]
    ]
  },
  {
    "id": "be6a963ad062c0fc",
    "type": "mqtt in",
    "z": "2428a61e85ba8239",
    "name": "mqtt接收平台数据",
    "topic": "aa",
    "qos": "2",
    "datatype": "auto-detect",
    "broker": "bf5a2e4e48b2bbdb",
    "nl": false,
    "rap": true,
    "rh": 0,
    "inputs": 0,
    "x": 550,
    "y": 580,
    "wires": [
      [
        "436f942a355f0fd2"
      ]
    ]
  },
  {
    "id": "436f942a355f0fd2",
    "type": "function",
    "z": "2428a61e85ba8239",
    "name": "function 3",
    "func": "\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 760,
    "y": 580,
    "wires": [
      [
        "d422aba0763898df"
      ]
    ]
  },
  {
    "id": "ef990144ca454bc7",
    "type": "tcp in",
    "z": "2428a61e85ba8239",
    "name": "",
    "server": "server",
    "host": "",
    "port": "9995",
    "datamode": "stream",
    "datatype": "buffer",
    "newline": "",
    "topic": "",
    "trim": false,
    "base64": false,
    "tls": "",
    "x": 260,
    "y": 1060,
    "wires": [
      [
        "b9f4db4bbe99eea3",
        "b0c2fde55e08bfe6",
        "12d5565bc57fc8cc"
      ]
    ]
  },
  {
    "id": "b0c2fde55e08bfe6",
    "type": "debug",
    "z": "2428a61e85ba8239",
    "name": "tcp接收",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 780,
    "y": 1060,
    "wires": []
  },
  {
    "id": "b9f4db4bbe99eea3",
    "type": "tcp out",
    "z": "2428a61e85ba8239",
    "name": "",
    "host": "",
    "port": "",
    "beserver": "reply",
    "base64": false,
    "end": false,
    "tls": "",
    "x": 950,
    "y": 860,
    "wires": []
  },
  {
    "id": "60bcd23b2853a918",
    "type": "inject",
    "z": "2428a61e85ba8239",
    "name": "定时读取15,15-2寄存器",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "[1,3,15,15,0,2,247,28]",
    "payloadType": "bin",
    "x": 340,
    "y": 860,
    "wires": [
      [
        "b9f4db4bbe99eea3"
      ]
    ]
  },
  {
    "id": "2299c2187b786e58",
    "type": "inject",
    "z": "2428a61e85ba8239",
    "name": "定时读取0,0-2寄存器",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "[1,3,0,0,0,2,196,11]",
    "payloadType": "bin",
    "x": 330,
    "y": 920,
    "wires": [
      [
        "b9f4db4bbe99eea3"
      ]
    ]
  },
  {
    "id": "ac24a2d2ce0e7b67",
    "type": "mqtt out",
    "z": "2428a61e85ba8239",
    "name": "将消息通过mqtt发送到平台",
    "topic": "",
    "qos": "",
    "retain": "",
    "respTopic": "",
    "contentType": "",
    "userProps": "",
    "correl": "",
    "expiry": "",
    "broker": "bf5a2e4e48b2bbdb",
    "x": 720,
    "y": 1160,
    "wires": []
  },
  {
    "id": "12d5565bc57fc8cc",
    "type": "function",
    "z": "2428a61e85ba8239",
    "name": "function 4",
    "func": "\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 500,
    "y": 1160,
    "wires": [
      [
        "ac24a2d2ce0e7b67"
      ]
    ]
  },
  {
    "id": "1879b2c21a384f7a",
    "type": "mqtt in",
    "z": "2428a61e85ba8239",
    "name": "mqtt接收平台数据",
    "topic": "aa",
    "qos": "2",
    "datatype": "auto-detect",
    "broker": "bf5a2e4e48b2bbdb",
    "nl": false,
    "rap": true,
    "rh": 0,
    "inputs": 0,
    "x": 530,
    "y": 980,
    "wires": [
      [
        "57f6d841a529574a"
      ]
    ]
  },
  {
    "id": "57f6d841a529574a",
    "type": "function",
    "z": "2428a61e85ba8239",
    "name": "function 5",
    "func": "\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 740,
    "y": 980,
    "wires": [
      [
        "b9f4db4bbe99eea3"
      ]
    ]
  },
  {
    "id": "bf5a2e4e48b2bbdb",
    "type": "mqtt-broker",
    "name": "thingspanel",
    "broker": "dev.thingspanel.cn",
    "port": "1883",
    "clientid": "",
    "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": {},
    "userProps": "",
    "sessionExpiry": ""
  }
]
插件信息
作者:
ThingsPanel
类别:
规则引擎
版本号:
v1.0
发布日期:
2023-07-28 14:32
Github
Gitee
微信交流群
QQ交流群
北京极益科技有限公司 版权所有 ICP:京ICP备15045763号-12