Just starting out on my Node Red journey and trying to build an intelligent solar PV switch and data logger. Switch and data logger is working fine. I'm using Influx DB to log, on a Pi Hassio platform. But having a real problem with something I thought was basic.
I got a query running which polls mean energy generation over the last 20 mins from Influx. This is the string returned.
I'm trying to get the data component highlighted. The mean valuw.
On the debug node, I'm getting "undefined".
This is the logic in the function node.
var arr = msg.payload;
for (var i = 0; i < arr.length; i++){
var obj = arr[i];
msg.payload = obj.mean;
}
return msg;
When posting this logic and the string in an online JS tool this code works and returns the value.
It is probably something very obvious, but I spent a lot of head scratching and got nowhere. It would be fab if you guys could take a look and maybe give me some pointers.
Thanks again, I've done that now. What would be the best function logic to get the mean value within the array? I've seen something like this used before, but it doesn't seem to work here.
p = msg.payload[0];
node.log(typeof p);
msg.payload = p.mean;