Modbus, DHT11, Display on webpage

Read temperature and humidity and make it available to Modbus master devices on the network. Display the same temperature and humidity with the gauge on a webpage Convert floating-point to the Modbus 16-bit registers.

This project gives you the basic understanding of how to use the Modbus library and the way to have floating-point numbers be transmitted to your clients. Utilizing the method for transferring data from floating-point to integer encoded floating-point and adding the arrays to complete a 16-bit array to be transmitted over Modbus.

It also has an example of how to combine two payload messages into a single payload message. it may be helpful to combine multiple payload messages into a single payload message especially if you have multiple sensors that you need to send out to your Modbus server or Modbus clients.

Hope this helps you save some time in your development

Make awesome things Thanks John Miller

[{"id":"80fcc379.93d85","type":"rpi-dht22","z":"d412f098.fe1bf","name":"dht11","topic":"dht11","dht":"11","pintype":"2","pin":"7","x":229.5,"y":137,"wires":[["6bac6e1f.07807","23b4eaf3.a34f86","a8ee19fc.3dd028","b4c4739.6a46b9"]]},{"id":"6bac6e1f.07807","type":"ui_text","z":"d412f098.fe1bf","group":"94d475f0.ab65f8","order":0,"width":0,"height":0,"name":"","label":"Temp C","format":"{{msg.payload}}","layout":"row-spread","x":387.5,"y":92,"wires":[]},{"id":"23b4eaf3.a34f86","type":"ui_text","z":"d412f098.fe1bf","group":"94d475f0.ab65f8","order":0,"width":0,"height":0,"name":"","label":"H %","format":"{{msg.humidity}}","layout":"row-spread","x":388.5,"y":159,"wires":[]},{"id":"c877c17a.50765","type":"ui_text","z":"d412f098.fe1bf","group":"94d475f0.ab65f8","order":0,"width":0,"height":0,"name":"","label":"Temp F","format":"{{msg.payload}}","layout":"row-spread","x":532.5,"y":92,"wires":[]},{"id":"a8ee19fc.3dd028","type":"function","z":"d412f098.fe1bf","name":"CtoF","func":"    var tempc = msg.payload;\n    tempf = tempc * 9/5 + 32;\n    tempf = Math.round(tempf * 10) / 10;\n    msg.payload = tempf;\n    return msg;","outputs":1,"noerr":0,"x":388.5,"y":126,"wires":[["c877c17a.50765","7d179214.52a95c","b5112c0c.9e92d"]]},{"id":"56f0920e.58887c","type":"interval","z":"d412f098.fe1bf","name":"interval","interval":"10","onstart":false,"msg":"ping","showstatus":true,"unit":"seconds","statusformat":"YYYY-MM-D HH:mm:ss","x":107,"y":159,"wires":[["80fcc379.93d85"]]},{"id":"7cc728e.a5f40d8","type":"modbus-server","z":"d412f098.fe1bf","name":"","logEnabled":false,"serverPort":"502","responseDelay":"50","delayUnit":"ms","coilsBufferSize":1024,"holdingBufferSize":1024,"inputBufferSize":1024,"x":200.5,"y":96.5,"wires":[[],[],[]]},{"id":"d2b5838f.a6b63","type":"modbus-write","z":"d412f098.fe1bf","name":"","showStatusActivities":true,"unitid":"","dataType":"MHoldingRegisters","adr":"0","quantity":"4","server":"61201c44.afaba4","x":827,"y":177,"wires":[[],[]]},{"id":"7d179214.52a95c","type":"function","z":"d412f098.fe1bf","name":"R32TO16w","func":"var value      = msg.payload\nvar buffer     = new ArrayBuffer(4);\nvar intView    = new Uint16Array(buffer);\nvar floatView  = new Float32Array(buffer);\nfloatView[0]   = value;\nmsg.payload    = [intView[1], intView[0]];\nmsg.topic=\"T\";\nreturn msg;","outputs":1,"noerr":0,"x":541,"y":124,"wires":[["39de3844.3c15a8"]]},{"id":"b4c4739.6a46b9","type":"function","z":"d412f098.fe1bf","name":"R32TO16w","func":"var value      = msg.humidity\nvar buffer     = new ArrayBuffer(4);\nvar intView    = new Uint16Array(buffer);\nvar floatView  = new Float32Array(buffer);\nfloatView[0]   = value;\nmsg.payload    = [intView[1], intView[0]];\nmsg.topic=\"H\";\nreturn msg;","outputs":1,"noerr":0,"x":407,"y":191,"wires":[["39de3844.3c15a8"]]},{"id":"39de3844.3c15a8","type":"function","z":"d412f098.fe1bf","name":"M AR","func":"context.data = context.data || new Object() ;\nswitch (msg.topic) {\n    case \"T\":\n        context.data.T = msg.payload;\n                break;\n    case \"H\":\n        context.data.H = msg.payload;\n                break;\n    default:\n           \tbreak;\n}\nif(context.data.T != null && context.data.H != null)\n{\n    Array.prototype.push.apply(context.data.T, context.data.H);\n    msg.payload = context.data.T\n    context.data=null;\n    return msg;\n} ","outputs":1,"noerr":0,"x":677,"y":178,"wires":[["d2b5838f.a6b63"]]},{"id":"b5112c0c.9e92d","type":"ui_gauge","z":"d412f098.fe1bf","name":"","group":"94d475f0.ab65f8","order":0,"width":0,"height":0,"gtype":"gage","title":"Gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"x":521.5,"y":156,"wires":[]},{"id":"94d475f0.ab65f8","type":"ui_group","z":"","name":"Temp G1","tab":"60e0a923.3783a8","disp":true,"width":"6"},{"id":"61201c44.afaba4","type":"modbus-client","z":"","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.1.114","tcpPort":"502","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":"60e0a923.3783a8","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

Flow Info

Created 7 years, 8 months ago
Rating: 5 1

Owner

Actions

Rate:

Node Types

Core
  • function (x4)
Other
  • interval (x1)
  • modbus-client (x1)
  • modbus-server (x1)
  • modbus-write (x1)
  • rpi-dht22 (x1)
  • ui_gauge (x1)
  • ui_group (x1)
  • ui_tab (x1)
  • ui_text (x3)

Tags

  • Modbus
  • dht11
  • dht22
  • merge
  • arrays
  • combine
  • join
  • payload
  • convert
  • ffloating-point
  • temperature
  • humidity
  • server
  • webpage
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option