Modbus Demo

Shows how to use node-red-contrib-modbus. This flow uses the Modbus Server, Modbus Read, and Modbus Write nodes. It also uses the Node-Red dashboard to create a simple user interface for writing and reading the value.

[{"id":"71e3cc07.ebf9b4","type":"modbus-read","z":"152fe1ef.7f71de","name":"read 1","showStatusActivities":false,"showErrors":false,"unitid":"1","dataType":"HoldingRegister","adr":"1","quantity":"1","rate":"5","rateUnit":"s","server":"db6f9b3e.e5f338","x":89.0000171661377,"y":437.00000381469727,"wires":[[],["7abba296.5c409c"]]},{"id":"c476c641.042418","type":"modbus-write","z":"152fe1ef.7f71de","name":"write","showStatusActivities":false,"showErrors":false,"unitid":"1","dataType":"HoldingRegister","adr":"1","quantity":"1","server":"db6f9b3e.e5f338","x":347.9943046569824,"y":603.4091277122498,"wires":[[],["427621e6.2f682"]]},{"id":"15c1a103.0ebd4f","type":"inject","z":"152fe1ef.7f71de","name":"","topic":"","payload":"24","payloadType":"num","repeat":"","crontab":"","once":false,"x":114.77837562561035,"y":579.3835296630859,"wires":[["c476c641.042418"]]},{"id":"427621e6.2f682","type":"debug","z":"152fe1ef.7f71de","name":"","active":false,"console":"false","complete":"false","x":527.9943466186523,"y":608.409101486206,"wires":[]},{"id":"7abba296.5c409c","type":"function","z":"152fe1ef.7f71de","name":" Decode array","func":"//   The message returned from the read node is an\n// array as there could be multiple registers returned\n//   This reads the first value in the array.\nm = msg.payload.data[0]\nreturn {payload: m};\n","outputs":1,"noerr":0,"x":270.7868766784668,"y":443.78411197662354,"wires":[["40d193e5.b31c4c","d8904a91.c71108","fb05e9f0.4216c8"]]},{"id":"40d193e5.b31c4c","type":"debug","z":"152fe1ef.7f71de","name":"","active":true,"console":"false","complete":"payload","x":531.0085639953613,"y":413.41481590270996,"wires":[]},{"id":"49bae4e7.6cc76c","type":"modbus-server","z":"152fe1ef.7f71de","name":"Modbus Server","logEnabled":false,"serverPort":10502,"responseDelay":100,"delayUnit":"ms","coilsBufferSize":1024,"holdingBufferSize":1024,"inputBufferSize":1024,"x":317.9999885559082,"y":105.99999761581421,"wires":[["27095842.c16878"],["27095842.c16878"],["27095842.c16878"]]},{"id":"27095842.c16878","type":"debug","z":"152fe1ef.7f71de","name":"","active":false,"console":"false","complete":"false","x":547.9999885559082,"y":105.99999761581421,"wires":[]},{"id":"974edd7b.5aeb6","type":"inject","z":"152fe1ef.7f71de","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":117.9999885559082,"y":105.99999761581421,"wires":[["49bae4e7.6cc76c"]]},{"id":"a1e12eaa.1a0ae","type":"comment","z":"152fe1ef.7f71de","name":"Creates a Modbus Slave device to read and write to","info":"","x":244.69999885559082,"y":63,"wires":[]},{"id":"7ea4ab1f.5aa314","type":"comment","z":"152fe1ef.7f71de","name":"Read modbus register(s)","info":"","x":161.00000381469727,"y":396.99997997283936,"wires":[]},{"id":"729684a3.3811dc","type":"comment","z":"152fe1ef.7f71de","name":"Write modbus register(s)","info":"","x":174.0000228881836,"y":545.9999990463257,"wires":[]},{"id":"fb05e9f0.4216c8","type":"ui_chart","z":"152fe1ef.7f71de","name":"","group":"1fc0c274.125a6e","order":2,"width":0,"height":0,"label":"Holding Register Chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"10","removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":563.7000198364258,"y":494.60007095336914,"wires":[[],[]]},{"id":"1fea8ee3.f44011","type":"ui_slider","z":"152fe1ef.7f71de","name":"","label":"Set Value","group":"1fc0c274.125a6e","order":3,"width":0,"height":0,"passthru":true,"topic":"","min":0,"max":"100","step":1,"x":121.70001983642578,"y":624.3999981880188,"wires":[["c476c641.042418","77537589.60958c"]]},{"id":"d8904a91.c71108","type":"ui_text","z":"152fe1ef.7f71de","group":"1fc0c274.125a6e","order":1,"width":0,"height":0,"name":"","label":"Holding Register","format":"{{msg.payload}}","layout":"row-spread","x":543.7000160217285,"y":457.3999824523926,"wires":[]},{"id":"77537589.60958c","type":"ui_text","z":"152fe1ef.7f71de","group":"1fc0c274.125a6e","order":4,"width":0,"height":0,"name":"","label":"Set Value","format":"{{msg.payload}}","layout":"row-spread","x":330.00000762939453,"y":652.9999842643738,"wires":[]},{"id":"ef1ff17b.cd3fe","type":"debug","z":"152fe1ef.7f71de","name":"","active":false,"console":"false","complete":"false","x":544.8333587646484,"y":309.01043128967285,"wires":[]},{"id":"ca982324.01be8","type":"modbus-flex-write","z":"152fe1ef.7f71de","name":"","showStatusActivities":false,"showErrors":true,"server":"48496f3b.10762","x":332.1173858642578,"y":303.6103162765503,"wires":[[],["ef1ff17b.cd3fe"]]},{"id":"ffc751c8.9750d","type":"inject","z":"152fe1ef.7f71de","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"x":112.00001525878906,"y":235.01056098937988,"wires":[["28a61341.912bdc","f08c1401.e2b0e8"]]},{"id":"c88810d6.ae4e","type":"function","z":"152fe1ef.7f71de","name":"Startup Values","func":"msg.payload = { value:[false, false, false, false], \n'fc': 15, \n'unitid': 1, \n'address': 0, \n'quantity': 4 } \nreturn msg","outputs":1,"noerr":0,"x":446.83331298828125,"y":220.67724800109863,"wires":[["ca982324.01be8"]]},{"id":"28a61341.912bdc","type":"delay","z":"152fe1ef.7f71de","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":265,"y":220.34393501281738,"wires":[["c88810d6.ae4e"]]},{"id":"1c39bdab.bc0ca2","type":"function","z":"152fe1ef.7f71de","name":"Startup Values","func":"msg.payload = { value:[100,90,100,200,100,200], \n'fc': 16, \n'unitid': 1, \n'address': 1, \n'quantity': 6 } \nreturn msg","outputs":1,"noerr":0,"x":446.83331298828125,"y":256.67724800109863,"wires":[["ca982324.01be8"]]},{"id":"f08c1401.e2b0e8","type":"delay","z":"152fe1ef.7f71de","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":265,"y":256.3439350128174,"wires":[["1c39bdab.bc0ca2"]]},{"id":"ed66618e.5bc3c","type":"comment","z":"152fe1ef.7f71de","name":"Startup Sim Values","info":"","x":141.7666778564453,"y":186.87725448608398,"wires":[]},{"id":"db6f9b3e.e5f338","type":"modbus-client","z":"","name":"local","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"10502","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},{"id":"1fc0c274.125a6e","type":"ui_group","z":"","name":"Modbus Test","tab":"91a58fa4.8a8b4","disp":true,"width":"6"},{"id":"48496f3b.10762","type":"modbus-client","z":"","name":"local","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"10502","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},{"id":"91a58fa4.8a8b4","type":"ui_tab","z":"","name":"Modbus","icon":"dashboard"}]
ElectronHacks

Flow Info

created 3 weeks, 4 days ago
updated 2 weeks, 2 days ago

Node Types

Core
  • comment (x4)
  • debug (x4)
  • delay (x2)
  • function (x3)
  • inject (x3)
Other

Tags

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