I'm trying to extract the temperature data from a DS18B20 sensor and squirt it to a gauge in node-red, the data package consists of three arrays with the temperature array being the middle one like this...
3/29/2018, 10:28:07 PMnode: 470f99b8.af54d8
msg.payload : string[79]
""{"Time":"2018-03-29T15:54:44","DS18B20":{"Temperature":19.81},"TempUnit":"C"}""
I have managed to 'get the job done' using three nodes - a split node to split the msg.payload into the three arrays, followed by a 'switch ' node to discard the two unwanted arrays, and then another 'switch' node to divide the array in half ( to remove the numbers in the sensor name and just leave the numbers in the temperature), this is then squirted into the Gauge and it works....but I would like to know if a function can be written in a function node to do the same job as it would be so much neater....but my java skills just aint up to it....
anyhow...fascinating subject with some real world applications...
My flow is here if you have node-red to squirt it into...
Code: Select all
[{"id":"4f197a36.c59b64","type":"mqtt in","z":"d2165ee4.b72c2","name":"DS18B20","topic":"tele/devboard_36/SENSOR","qos":"1","broker":"a5e63177.c349e","x":180,"y":140,"wires":[["bb3e5886.70c988","470f99b8.af54d8","2f587818.304318"]]},{"id":"bb3e5886.70c988","type":"split","z":"d2165ee4.b72c2","name":"","splt":",","spltType":"str","arraySplt":"1","arraySpltType":"len","stream":false,"addname":"","x":370,"y":140,"wires":[["d68f40dd.61198"]]},{"id":"d68f40dd.61198","type":"switch","z":"d2165ee4.b72c2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"\"humidity\":","vt":"str"},{"t":"cont","v":"\"pressure\":","vt":"str"},{"t":"cont","v":"\"altitude\":","vt":"str"},{"t":"cont","v":"\"Temperature\":","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":510,"y":180,"wires":[[],[],[],["62cc7c84.de4ad4"]]},{"id":"7de28cd4.872c14","type":"ui_gauge","z":"d2165ee4.b72c2","name":"","group":"5a7a9a72.f6d7c4","order":0,"width":0,"height":0,"gtype":"gage","title":"Water Temperature","label":"C","format":"{{value}}","min":0,"max":"40","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":830,"y":240,"wires":[]},{"id":"62cc7c84.de4ad4","type":"split","z":"d2165ee4.b72c2","name":"","splt":"25","spltType":"len","arraySplt":"1","arraySpltType":"len","stream":false,"addname":"","x":650,"y":220,"wires":[["7de28cd4.872c14"]]},{"id":"470f99b8.af54d8","type":"debug","z":"d2165ee4.b72c2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":390,"y":80,"wires":[]},{"id":"2f587818.304318","type":"function","z":"d2165ee4.b72c2","name":"?????","func":"What goes in here?","outputs":1,"noerr":4,"x":490,"y":340,"wires":[["7de28cd4.872c14"]]},{"id":"a5e63177.c349e","type":"mqtt-broker","z":"","name":"localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"5a7a9a72.f6d7c4","type":"ui_group","z":"","name":"Water Temperature","tab":"fa121ba6.b36f38","order":3,"disp":true,"width":"6","collapse":false},{"id":"fa121ba6.b36f38","type":"ui_tab","z":"","name":"Pool","icon":"dashboard","order":4}]