i have payload as follows and i want extract only last number. how?
string[304] Temperature 34.0 CPU Core #1 38.0 CPU Core #2 42.0 CPU Core #3 36.0 Temperature 30.0 Temperature 36.0 CPU Core #4 37.0 CPU Package 43.0 Temperature 34.0 CPU Core #1 38.0 CPU Core #2 42.0 CPU Core #3 36.0 Temperature 30.0 Temperature 36.0 CPU Core #4 37.0 CPU Package 43.0
Dujith
(Charles Evers)
October 10, 2021, 10:12am
2
Where does this come from? is the original message a json?
Because that would be the better way to get a single data value.
Hellis81
(Hellis81)
October 10, 2021, 11:02am
3
Untested but I think this could work.
In a function node:
var arr = msg.payload.split("\n");
msg.last = arr[arr.length-1];
return msg;
Dujith
(Charles Evers)
October 10, 2021, 2:02pm
5
What is sending out that message? What node are u using to get and send the information?
Hellis81
(Hellis81)
October 10, 2021, 4:54pm
6
So it seems it’s not spaces as your initial post suggested, it’s new lines.
Split on "\n"
instead
exec node
[ { "id": "22034ba2f0fa0df1", "type": "exec", "z": "8868d38e64b14e89", "command": "py C:\\Users\\User\\Desktop\\cputempwmiophw.py ", "addpay": "", "append": "", "useSpawn": "false", "timer": "", "winHide": false, "oldrc": false, "name": "", "x": 600, "y": 900, "wires": [ [ "729e1e1cf484923a", "869c5b9c0039b1f7", "dadcefc6b05f3337" ], [ "a522002a9baa2d36" ], [ "eba5f2cda47d53eb" ] ] } ]
thank you guys, got it working!