Skip to content

Node-RED Flow Examples

How to configure Modbus to read one or multiple variables?

Copy this flow and take it to Node-Red.

[
   {
      "id":"dcb2b5f5.8fec68",
      "type":"tab",
      "label":"Modbus example reading one and many variables",
      "disabled":false,
      "info":""
   },
   {
      "id":"e3e8bcc9.36905",
      "type":"modbus-flex-getter",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "showStatusActivities":true,
      "showErrors":true,
      "logIOActivities":false,
      "server":"3a2ff8b8.745db8",
      "useIOFile":false,
      "ioFile":"",
      "useIOForPayload":false,
      "emptyMsgOnFail":false,
      "keepMsgProperties":false,
      "x":550,
      "y":320,
      "wires":[
         [
            "d572ac19.9596c"
         ],
         [
            "3dbd0c17.105264"
         ]
      ]
   },
   {
      "id":"d572ac19.9596c",
      "type":"debug",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "active":false,
      "tosidebar":true,
      "console":false,
      "tostatus":false,
      "complete":"false",
      "x":790,
      "y":260,
      "wires":[

      ]
   },
   {
      "id":"3dbd0c17.105264",
      "type":"debug",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "active":true,
      "tosidebar":true,
      "console":false,
      "tostatus":false,
      "complete":"false",
      "x":790,
      "y":380,
      "wires":[

      ]
   },
   {
      "id":"6f1e2f10.34d8a",
      "type":"function",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "func":"msg.payload = {\n    'unitid': 72,\n    'fc': 4,\n    'address': 2,\n    'quantity': 2\n};\n\nreturn msg;",
      "outputs":1,
      "noerr":0,
      "x":350,
      "y":320,
      "wires":[
         [
            "e3e8bcc9.36905"
         ]
      ]
   },
   {
      "id":"95572790.530488",
      "type":"inject",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "topic":"",
      "payload":"",
      "payloadType":"date",
      "repeat":"",
      "crontab":"",
      "once":false,
      "onceDelay":0.1,
      "x":190,
      "y":260,
      "wires":[
         [
            "6f1e2f10.34d8a"
         ]
      ]
   },
   {
      "id":"2cd367ae.0750e8",
      "type":"file in",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "filename":"/home/root/modbus_sem3_map.csv",
      "format":"utf8",
      "chunk":false,
      "sendError":false,
      "encoding":"none",
      "x":440,
      "y":740,
      "wires":[
         [
            "3215b517.f13e3a"
         ]
      ]
   },
   {
      "id":"3215b517.f13e3a",
      "type":"csv",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "sep":",",
      "hdrin":true,
      "hdrout":true,
      "multi":"one",
      "ret":"\\n",
      "temp":"unitid,fc,address,quantity",
      "skip":"0",
      "x":690,
      "y":740,
      "wires":[
         [
            "e46f0449.257a88"
         ]
      ]
   },
   {
      "id":"f2fe25d8.7ef1e8",
      "type":"inject",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "topic":"",
      "payload":"",
      "payloadType":"date",
      "repeat":"",
      "crontab":"",
      "once":false,
      "onceDelay":0.1,
      "x":200,
      "y":660,
      "wires":[
         [
            "2cd367ae.0750e8"
         ]
      ]
   },
   {
      "id":"e46f0449.257a88",
      "type":"modbus-flex-getter",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "showStatusActivities":true,
      "showErrors":true,
      "logIOActivities":false,
      "server":"3a2ff8b8.745db8",
      "useIOFile":false,
      "ioFile":"",
      "useIOForPayload":false,
      "emptyMsgOnFail":false,
      "keepMsgProperties":false,
      "x":890,
      "y":740,
      "wires":[
         [
            "5de73e97.8e41a",
            "9fd3224d.16b56"
         ],
         [

         ]
      ]
   },
   {
      "id":"5de73e97.8e41a",
      "type":"debug",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "active":true,
      "tosidebar":true,
      "console":false,
      "tostatus":false,
      "complete":"false",
      "x":1130,
      "y":640,
      "wires":[

      ]
   },
   {
      "id":"9fd3224d.16b56",
      "type":"csv",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "sep":",",
      "hdrin":false,
      "hdrout":false,
      "multi":"one",
      "ret":"\\n",
      "temp":"",
      "skip":"0",
      "x":1110,
      "y":800,
      "wires":[
         [
            "fc25b07c.27758"
         ]
      ]
   },
   {
      "id":"fc25b07c.27758",
      "type":"file",
      "z":"dcb2b5f5.8fec68",
      "name":"",
      "filename":"/home/root/modbus_sem3_result.csv",
      "appendNewline":false,
      "createDir":false,
      "overwriteFile":"false",
      "encoding":"none",
      "x":1390,
      "y":800,
      "wires":[
         [

         ]
      ]
   },
   {
      "id":"ea37a113.97ce2",
      "type":"comment",
      "z":"dcb2b5f5.8fec68",
      "name":"Reading a single variable",
      "info":"",
      "x":250,
      "y":160,
      "wires":[

      ]
   },
   {
      "id":"136ff60b.e868aa",
      "type":"comment",
      "z":"dcb2b5f5.8fec68",
      "name":"Reading many variables from CSV file",
      "info":"",
      "x":270,
      "y":560,
      "wires":[

      ]
   },
   {
      "id":"2f19d7ad.54de58",
      "type":"comment",
      "z":"dcb2b5f5.8fec68",
      "name":"HERE is content of file modbus_sem3_map.csv",
      "info":"unitid,fc,address,quantity\n72,3,1,1\n72,3,7,1\n72,3,8,1\n72,3,9,2\n72,3,12,1\n72,4,2,2\n72,4,4,2\n72,4,6,2\n72,4,8,2\n72,4,10,2\n72,4,12,2\n72,4,38,2\n72,4,40,2\n72,4,60,2",
      "x":440,
      "y":800,
      "wires":[

      ]
   },
   {
      "id":"3a2ff8b8.745db8",
      "type":"modbus-client",
      "z":"",
      "name":"",
      "clienttype":"simpleser",
      "bufferCommands":true,
      "stateLogEnabled":false,
      "queueLogEnabled":false,
      "tcpHost":"127.0.0.1",
      "tcpPort":"502",
      "tcpType":"DEFAULT",
      "serialPort":"/dev/ttymxc4",
      "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
   }
]