Msg.payload.match(/(\d+|\d+\.\d+)'/)[1];

Hi,
how do you read this:
const value = msg.payload.match(/(\d+|\d+.\d+)'/)[1];
What it actually do?

 [{"id":"eddc8443.543858","type":"function","z":"2999a896.215b18","name":"Parse Temp","func":"const value = msg.payload.match(/(\\d+|\\d+\\.\\d+)'/)[1];\nmsg.value = value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":121,"wires":[["8dabd8a2.836bd8","e0785d64.06654","7fb72146.0dcd"]]}] 

I am trying to read the CPU temperature with the EXEC node,
as output I get this string:
temp=65.0'C
I need to read the 65 as a number.... to build a graph and test the different cooling systems.
could you direct me where I can learn something about this solution?

Thanks in advance for your time

It is matching an pattern in msg,payload using the javascript match function/method.
Edit/
It is matching whole numbers or decimal numbers, and returns the second arrayv alue using the[1]
/Edit

A good guide on regex.

I wouldn't do it that way, I would use
msg.value = msg.payload.split(/=|'/)[1]
or if you want it as a number rather than a string
msg.value = Number(msg.payload.split(/=|'/)[1])
The character after the | should be whatever is in your string after the number.
It works by splitting the string at the = and ' into a three element array, then taking the middle one which contains the number.

Thanks I got it now.

msg.payload = parseFloat(msg.payload.toFixed(5 , 9))

What about this solution?
Thanks for your previous suggestion

Hi, is it possible to filter the signals from an Arduino (kind of Average of 10-20 consecutive values) to avoid those spikes in the graph?

[{"id":"b1345a0f.4b32e8","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"a42c5f00.574e3","type":"exec","z":"b1345a0f.4b32e8","command":"vcgencmd measure_temp","addpay":false,"append":"","useSpawn":"false","timer":"","name":"Temp","x":470,"y":60,"wires":[["7b4131f2.33a02"],[],[]]},{"id":"27ba5e66.1ce602","type":"inject","z":"b1345a0f.4b32e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"2","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":150,"y":120,"wires":[["d5da6f53.6c59e","a42c5f00.574e3","c6613dc2.b0914"]]},{"id":"7b4131f2.33a02","type":"function","z":"b1345a0f.4b32e8","name":"SubString","func":"str = msg.payload \nmsg.payload  = str.substring(5, 9);\nreturn msg;","outputs":1,"noerr":0,"x":608,"y":47,"wires":[["73a7ab8.7b3c054"]]},{"id":"73a7ab8.7b3c054","type":"ui_gauge","z":"b1345a0f.4b32e8","name":"T CPU","group":"dcafe6e8.d5e7c8","order":1,"width":6,"height":6,"gtype":"gage","title":"CPU Temp.","label":"�C","format":"{{value}}","min":0,"max":"90","colors":["#00b500","#b6e203","#ca3838"],"seg1":"","seg2":"","x":751,"y":47,"wires":[]},{"id":"d5da6f53.6c59e","type":"exec","z":"b1345a0f.4b32e8","command":"top -d 0.5 -b -n2 | grep \"Cpu(s)\"|tail -n 1 | awk '{print $2 + $4}'","addpay":false,"append":"","useSpawn":"","timer":"","name":"LOAD","x":468,"y":121.5,"wires":[["f2803840.ce0988"],[],[]]},{"id":"f2803840.ce0988","type":"ui_gauge","z":"b1345a0f.4b32e8","name":"CPU LOAD","group":"dcafe6e8.d5e7c8","order":2,"width":6,"height":6,"gtype":"donut","title":"CPU LOAD","label":"%","format":"{{value}}","min":0,"max":"90","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":734,"y":107,"wires":[]},{"id":"c6613dc2.b0914","type":"exec","z":"b1345a0f.4b32e8","command":"free | grep Mem | awk '{print 100*($4+$6+$7)/$2}'","addpay":false,"append":"","useSpawn":"","timer":"","name":"MEM","x":471,"y":190,"wires":[["adb33532.f6a2a8"],[],[]]},{"id":"adb33532.f6a2a8","type":"ui_text","z":"b1345a0f.4b32e8","group":"dcafe6e8.d5e7c8","order":3,"width":6,"height":1,"name":"","label":"Free Memory :","format":"{{msg.payload}}%","layout":"row-center","x":726,"y":177,"wires":[]},{"id":"8c2d6d6f.6892d","type":"ui_chart","z":"b1345a0f.4b32e8","name":"","group":"88b7f0ed.7c69d","order":1,"width":14,"height":6,"label":"T","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"20","removeOlder":"4","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#28b31e","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":730,"y":360,"wires":[[]]},{"id":"2329919c.fa8c4e","type":"debug","z":"b1345a0f.4b32e8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":540,"wires":[]},{"id":"ea44f8cf.4383a8","type":"arduino in","z":"b1345a0f.4b32e8","name":"H1","pin":"0","state":"ANALOG","arduino":"df9af210.c7478","x":150,"y":500,"wires":[["83c663cb.e7786"]]},{"id":"1fb25bae.9efa84","type":"ui_gauge","z":"b1345a0f.4b32e8","name":"","group":"6e3a8a73.0f1f14","order":2,"width":7,"height":6,"gtype":"gage","title":"H","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#00b500","#00b500"],"seg1":"","seg2":"","x":730,"y":500,"wires":[]},{"id":"53bfc74d.3e7dd8","type":"function","z":"b1345a0f.4b32e8","name":"","func":"msg.payload = msg.payload * 100/1024 +2;\nmsg.payload = parseFloat(msg.payload.toFixed(1))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":500,"wires":[["1fb25bae.9efa84","2329919c.fa8c4e","dec125e5.77acd8"]]},{"id":"458e936c.69d71c","type":"arduino in","z":"b1345a0f.4b32e8","name":"T1","pin":"7","state":"ANALOG","arduino":"df9af210.c7478","x":150,"y":400,"wires":[["54b1a84d.abf3e8","45a02ea5.88489"]]},{"id":"f9cacc6f.84e7e","type":"ui_gauge","z":"b1345a0f.4b32e8","name":"","group":"6e3a8a73.0f1f14","order":1,"width":7,"height":6,"gtype":"gage","title":"T","label":"units","format":"{{value}}","min":0,"max":"20","colors":["#00a7b3","#0fe600","#ca3838"],"seg1":"10","seg2":"16","x":730,"y":400,"wires":[]},{"id":"3c68877a.feef48","type":"range","z":"b1345a0f.4b32e8","minin":"0","maxin":"1023","minout":"-40","maxout":"125","action":"scale","round":false,"property":"payload","name":"","x":440,"y":400,"wires":[["753f0a54.fbfff4"]]},{"id":"753f0a54.fbfff4","type":"function","z":"b1345a0f.4b32e8","name":"","func":"// msg.payload = msg.payload + 6;\nmsg.payload = parseFloat(msg.payload.toFixed(1))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":400,"wires":[["f9cacc6f.84e7e","38c2da9d.69bbe6","8c2d6d6f.6892d"]]},{"id":"54b1a84d.abf3e8","type":"timeframerlt","z":"b1345a0f.4b32e8","name":"","throttleType":"count","timeLimit":"2","timeLimitType":"seconds","countLimit":"50","byresetcountLimit":0,"x":290,"y":400,"wires":[["3c68877a.feef48"]]},{"id":"83c663cb.e7786","type":"timeframerlt","z":"b1345a0f.4b32e8","name":"","throttleType":"count","timeLimit":"2","timeLimitType":"seconds","countLimit":"50","byresetcountLimit":0,"x":290,"y":500,"wires":[["53bfc74d.3e7dd8"]]},{"id":"38c2da9d.69bbe6","type":"debug","z":"b1345a0f.4b32e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":440,"wires":[]},{"id":"dec125e5.77acd8","type":"ui_chart","z":"b1345a0f.4b32e8","name":"","group":"88b7f0ed.7c69d","order":2,"width":14,"height":6,"label":"H","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"4","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1277bf","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":730,"y":580,"wires":[[]]},{"id":"bb24cd42.15123","type":"ui_chart","z":"b1345a0f.4b32e8","name":"","group":"88b7f0ed.7c69d","order":3,"width":14,"height":6,"label":"T2","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"10","ymax":"30","removeOlder":"4","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#525456","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":730,"y":640,"wires":[[]]},{"id":"60ee2ce4.8c8424","type":"debug","z":"b1345a0f.4b32e8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":820,"wires":[]},{"id":"86447cbb.979d4","type":"arduino in","z":"b1345a0f.4b32e8","name":"H2","pin":"6","state":"ANALOG","arduino":"df9af210.c7478","x":150,"y":800,"wires":[["bcf00c02.2071f"]]},{"id":"d1a32e6e.40775","type":"ui_gauge","z":"b1345a0f.4b32e8","name":"","group":"6e3a8a73.0f1f14","order":4,"width":7,"height":6,"gtype":"gage","title":"H2","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#00b500","#00b500"],"seg1":"","seg2":"","x":730,"y":780,"wires":[]},{"id":"b00325d0.18b688","type":"function","z":"b1345a0f.4b32e8","name":"","func":"msg.payload = msg.payload * 100/1024 +2;\nmsg.payload = parseFloat(msg.payload.toFixed(1))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":800,"wires":[["d1a32e6e.40775","60ee2ce4.8c8424","a8e39b7d.ccbce8"]]},{"id":"e4ff590a.d9c548","type":"arduino in","z":"b1345a0f.4b32e8","name":"T2","pin":"5","state":"ANALOG","arduino":"df9af210.c7478","x":150,"y":680,"wires":[["98e9c75.550fb38"]]},{"id":"8c0ea3b2.59dbc","type":"ui_gauge","z":"b1345a0f.4b32e8","name":"","group":"6e3a8a73.0f1f14","order":3,"width":7,"height":6,"gtype":"gage","title":"T2","label":"units","format":"{{value}}","min":"12","max":"30","colors":["#00a7b3","#00e60f","#ca3838"],"seg1":"15","seg2":"22","x":730,"y":680,"wires":[]},{"id":"8631b5dd.fac4b8","type":"range","z":"b1345a0f.4b32e8","minin":"0","maxin":"1023","minout":"-40","maxout":"125","action":"scale","round":false,"property":"payload","name":"","x":440,"y":680,"wires":[["b5907f7f.a947d"]]},{"id":"b5907f7f.a947d","type":"function","z":"b1345a0f.4b32e8","name":"","func":"// msg.payload = msg.payload + 6;\nmsg.payload = parseFloat(msg.payload.toFixed(1))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":680,"wires":[["8c0ea3b2.59dbc","aaa94c40.04646","bb24cd42.15123"]]},{"id":"98e9c75.550fb38","type":"timeframerlt","z":"b1345a0f.4b32e8","name":"","throttleType":"count","timeLimit":"2","timeLimitType":"seconds","countLimit":"50","byresetcountLimit":0,"x":290,"y":680,"wires":[["8631b5dd.fac4b8"]]},{"id":"bcf00c02.2071f","type":"timeframerlt","z":"b1345a0f.4b32e8","name":"","throttleType":"count","timeLimit":"2","timeLimitType":"seconds","countLimit":"50","byresetcountLimit":0,"x":290,"y":800,"wires":[["b00325d0.18b688"]]},{"id":"aaa94c40.04646","type":"debug","z":"b1345a0f.4b32e8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":720,"wires":[]},{"id":"a8e39b7d.ccbce8","type":"ui_chart","z":"b1345a0f.4b32e8","name":"","group":"88b7f0ed.7c69d","order":4,"width":14,"height":6,"label":"H2","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"4","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#d9e70d","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":730,"y":860,"wires":[[]]},{"id":"6a933e35.1c856","type":"ui_button","z":"b1345a0f.4b32e8","name":"","group":"3b2f9f80.61f88","order":18,"width":1,"height":1,"passthru":false,"label":"","tooltip":"","color":"red","bgcolor":"","icon":"fa-heartbeat fa-2x","payload":"true","payloadType":"bool","topic":"","x":390,"y":740,"wires":[["f78aa1d3.7b87b"]],"info":"msg.payload =  [];\r\nreturn msg;"},{"id":"f78aa1d3.7b87b","type":"function","z":"b1345a0f.4b32e8","name":"reset","func":"msg.payload =  [];\nreturn msg;\n","outputs":1,"noerr":0,"x":510,"y":740,"wires":[["a8e39b7d.ccbce8","bb24cd42.15123"]]},{"id":"e5284fb0.67817","type":"ui_button","z":"b1345a0f.4b32e8","name":"","group":"3b2f9f80.61f88","order":6,"width":1,"height":1,"passthru":false,"label":"","tooltip":"","color":"red","bgcolor":"","icon":"fa-heartbeat fa-2x","payload":"true","payloadType":"bool","topic":"","x":410,"y":460,"wires":[["73d5a2bf.a99c3c"]],"info":"msg.payload =  [];\r\nreturn msg;"},{"id":"73d5a2bf.a99c3c","type":"function","z":"b1345a0f.4b32e8","name":"reset","func":"msg.payload =  [];\nreturn msg;\n","outputs":1,"noerr":0,"x":530,"y":460,"wires":[["8c2d6d6f.6892d","dec125e5.77acd8"]]},{"id":"45a02ea5.88489","type":"average","z":"b1345a0f.4b32e8","name":"","topic":"","x":280,"y":320,"wires":[[]]},{"id":"dcafe6e8.d5e7c8","type":"ui_group","z":"","name":"Load","tab":"6ae5d47e.90eaac","order":1,"disp":false,"width":"6"},{"id":"88b7f0ed.7c69d","type":"ui_group","z":"","name":"Graph","tab":"6ae5d47e.90eaac","order":3,"disp":false,"width":14,"collapse":false},{"id":"df9af210.c7478","type":"arduino-board","z":"","device":"/dev/ttyACM0"},{"id":"6e3a8a73.0f1f14","type":"ui_group","z":"","name":"T-H","tab":"6ae5d47e.90eaac","order":4,"disp":true,"width":7,"collapse":false},{"id":"3b2f9f80.61f88","type":"ui_group","z":"","name":"Reset","tab":"6ae5d47e.90eaac","order":2,"disp":true,"width":1,"collapse":false},{"id":"6ae5d47e.90eaac","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}]

see the node-red-node-smooth node

thanks. much appreciated

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.