node-red-contrib-modbus example flow

Example flow from 3.0.0 and above - since v0.17.5 of Node-RED, please try also the Node-RED->Import->Examples->modbus

[
  {
    "id": "278c3ffc.fa40d8",
    "type": "tab",
    "label": "Modbus HTTP",
    "disabled": false,
    "info": ""
  },
  {
    "id": "f4e4d112.5e3708",
    "type": "modbus-getter",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "showStatusActivities": false,
    "showErrors": false,
    "unitid": "",
    "dataType": "HoldingRegister",
    "adr": "0",
    "quantity": "4",
    "server": "228160dd.0bd268",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "x": 410,
    "y": 190,
    "wires": [
      [
        "18f09288.c552b5",
        "b3bee6f8.64944"
      ],
      [
        "f61cd2bb.db0808"
      ]
    ]
  },
  {
    "id": "867bcf5a.728988",
    "type": "http in",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "url": "/modbus/flex/read",
    "method": "get",
    "upload": false,
    "swaggerDoc": "",
    "x": 190,
    "y": 340,
    "wires": [
      [
        "a06133ba.054e9"
      ]
    ]
  },
  {
    "id": "18f09288.c552b5",
    "type": "debug",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "true",
    "x": 770,
    "y": 130,
    "wires": []
  },
  {
    "id": "f61cd2bb.db0808",
    "type": "modbus-response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "registerShowMax": 20,
    "x": 680,
    "y": 170,
    "wires": []
  },
  {
    "id": "a06133ba.054e9",
    "type": "modbus-flex-getter",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "showStatusActivities": false,
    "showErrors": false,
    "server": "228160dd.0bd268",
    "x": 430,
    "y": 340,
    "wires": [
      [
        "4c623588.f2d704",
        "ad5c1f3d.c60f"
      ],
      [
        "d42d9e3.9a23ae"
      ]
    ]
  },
  {
    "id": "d42d9e3.9a23ae",
    "type": "modbus-response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "registerShowMax": 20,
    "x": 670,
    "y": 330,
    "wires": []
  },
  {
    "id": "4c623588.f2d704",
    "type": "debug",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "true",
    "x": 750,
    "y": 290,
    "wires": []
  },
  {
    "id": "33c8f5aa.a03022",
    "type": "catch",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "scope": null,
    "x": 650,
    "y": 80,
    "wires": [
      [
        "df84382d.4327b8"
      ]
    ]
  },
  {
    "id": "ad380629.c0b74",
    "type": "modbus-flex-server",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "logEnabled": false,
    "serverPort": "18502",
    "responseDelay": 100,
    "unitId": 1,
    "delayUnit": "ms",
    "coilsBufferSize": 20000,
    "registersBufferSize": 20000,
    "minAddress": 0,
    "splitAddress": 10000,
    "funcGetCoil": "function getFlexCoil(addr, unitID) {\n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\treturn node.coils.readUInt8(addr * node.bufferFactor) \n\t}  \n}",
    "funcGetInputRegister": "function getFlexInputRegister(addr, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress) { \n\n\t\treturn node.registers.readUInt16BE(addr * node.bufferFactor)  \n\t} \n}",
    "funcGetHoldingRegister": "function getFlexHoldingRegsiter(addr, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr > node.splitAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\treturn node.registers.readUInt16BE(addr * node.bufferFactor)  \n\t} \n}",
    "funcSetCoil": "function setFlexCoil(addr, value, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\tnode.coils.writeUInt8(value, addr * node.bufferFactor)  \n\t} \n}",
    "funcSetRegister": "function setFlexRegister(addr, value, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\tnode.registers.writeUInt16BE(value, addr * node.bufferFactor)  \n\t} \n}",
    "x": 200,
    "y": 70,
    "wires": [
      [],
      [],
      []
    ]
  },
  {
    "id": "ad5c1f3d.c60f",
    "type": "http response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "statusCode": "",
    "headers": {},
    "x": 630,
    "y": 290,
    "wires": []
  },
  {
    "id": "f566f9bf.dbec68",
    "type": "http in",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "url": "/modbus/read",
    "method": "get",
    "upload": false,
    "swaggerDoc": "",
    "x": 180,
    "y": 190,
    "wires": [
      [
        "f4e4d112.5e3708"
      ]
    ]
  },
  {
    "id": "b3bee6f8.64944",
    "type": "http response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "statusCode": "",
    "headers": {},
    "x": 640,
    "y": 130,
    "wires": []
  },
  {
    "id": "df84382d.4327b8",
    "type": "debug",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "true",
    "x": 800,
    "y": 80,
    "wires": []
  },
  {
    "id": "af9361fe.87ea18",
    "type": "modbus-flex-write",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "showStatusActivities": false,
    "showErrors": false,
    "server": "228160dd.0bd268",
    "x": 420,
    "y": 530,
    "wires": [
      [
        "3540312d.5017c6"
      ],
      [
        "b0288009.f96ae8"
      ]
    ]
  },
  {
    "id": "fdbc5e3e.e35fb8",
    "type": "modbus-write",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "showStatusActivities": false,
    "showErrors": false,
    "unitid": "",
    "dataType": "HoldingRegister",
    "adr": "0",
    "quantity": "1",
    "server": "228160dd.0bd268",
    "x": 410,
    "y": 440,
    "wires": [
      [
        "b33411ba.b3b498"
      ],
      [
        "75fa26b3.414c"
      ]
    ]
  },
  {
    "id": "4f9b6223.e98aa4",
    "type": "http in",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "url": "/modbus/write",
    "method": "get",
    "upload": false,
    "swaggerDoc": "",
    "x": 180,
    "y": 440,
    "wires": [
      [
        "fdbc5e3e.e35fb8"
      ]
    ]
  },
  {
    "id": "b33411ba.b3b498",
    "type": "http response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "statusCode": "",
    "headers": {},
    "x": 640,
    "y": 400,
    "wires": []
  },
  {
    "id": "75fa26b3.414c",
    "type": "modbus-response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "registerShowMax": 20,
    "x": 680,
    "y": 440,
    "wires": []
  },
  {
    "id": "1e4aafb.8f1855",
    "type": "http in",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "url": "/modbus/flex/write",
    "method": "get",
    "upload": false,
    "swaggerDoc": "",
    "x": 190,
    "y": 530,
    "wires": [
      [
        "af9361fe.87ea18"
      ]
    ]
  },
  {
    "id": "3540312d.5017c6",
    "type": "http response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "statusCode": "",
    "headers": {},
    "x": 640,
    "y": 490,
    "wires": []
  },
  {
    "id": "b0288009.f96ae8",
    "type": "modbus-response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "registerShowMax": 20,
    "x": 680,
    "y": 530,
    "wires": []
  },
  {
    "id": "69788b37.05c614",
    "type": "comment",
    "z": "278c3ffc.fa40d8",
    "name": "HTTP request GET working examples",
    "info": "## Read\n\n### Flex Read\n\nhttp://localhost:1880/modbus/flex/read?value=0&unitid=1&fc=3&address=0&quantity=1\n\nhttp://localhost:1880/modbus/flex/read?value=0&unitid=1&fc=4&address=0&quantity=1\n\nhttp://localhost:1880/modbus/flex/read?value=0&unitid=1&fc=3&address=0&quantity=5\n\nhttp://localhost:1880/modbus/flex/read?value=0&unitid=1&fc=4&address=0&quantity=5\n\n### Read\n\nhttp://localhost:1880/modbus/read\n\n## Write\n\n### Test HTTP without Modbus\n\nhttp://localhost:1880/modbus/flex/write/test?value=[1,2,3,4,5]&unitid=1&fc=16&address=0&quantity=5\n\n\n### Flex Write\n\nhttp://localhost:1880/modbus/flex/write?value=10&unitid=1&fc=6&address=0&quantity=1\n\nhttp://localhost:1880/modbus/flex/write?value=[1,2,3,4,5]&unitid=1&fc=16&address=0&quantity=5\n\n### Write\n\nhttp://localhost:1880/modbus/write\n",
    "x": 240,
    "y": 140,
    "wires": []
  },
  {
    "id": "a3dd6f31.9eb17",
    "type": "http in",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "url": "/modbus/flex/write/test",
    "method": "get",
    "upload": false,
    "swaggerDoc": "",
    "x": 220,
    "y": 620,
    "wires": [
      [
        "efac3450.e15668"
      ]
    ]
  },
  {
    "id": "d88e2d99.cd96e",
    "type": "debug",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "true",
    "x": 590,
    "y": 620,
    "wires": []
  },
  {
    "id": "efac3450.e15668",
    "type": "function",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "func": "if (msg.payload.value && msg.payload.value.indexOf(',') > -1) {\n    msg.payload.value = JSON.parse(msg.payload.value)\n}\n\nif (msg.value && msg.value.indexOf(',') > -1) {\n    msg.value = JSON.parse(msg.payload.value)\n}\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "x": 450,
    "y": 620,
    "wires": [
      [
        "d88e2d99.cd96e",
        "d20d5d26.f4c1a"
      ]
    ]
  },
  {
    "id": "d20d5d26.f4c1a",
    "type": "http response",
    "z": "278c3ffc.fa40d8",
    "name": "",
    "statusCode": "",
    "headers": {},
    "x": 590,
    "y": 660,
    "wires": []
  },
  {
    "id": "228160dd.0bd268",
    "type": "modbus-client",
    "z": "278c3ffc.fa40d8",
    "name": "Modbus Flex Server",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "tcpHost": "127.0.0.1",
    "tcpPort": "18502",
    "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",
    "reconnectTimeout": "2000"
  }
]
biancode

Flow Info

created 2 years, 6 months ago
updated 1 year ago

Node Types

Core
  • catch (x1)
  • comment (x1)
  • debug (x4)
  • function (x1)
  • http in (x5)
  • http response (x5)
Other

Tags

  • modbus
  • serial
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option