Been trying to solve this for close to a day now.
Found this thread dealing with the topic and @hardillb, gave a solution.
text
I still can’t wrap my head around it.
You can not add 2 JavaScript objects together. If you want to add the 2 msg.payload values you need to explicitly add those 2 variables.
And gives this solution
var msgAll = { payload: msg.payload};
var msg0 = { payload :msg.payload[0] };
var msg1 = { payload :msg.payload[1] };
var msg2 = {payload: msg0.payload + msg1.payload};
return [ msg0, msg1, msg2];
This is my functions input msg
{"topic":"Node-RED/CerboGX-MK2/MPPT250-100-1/PV-Current(A)","payload":[{"value":3.619999885559082},{"value":39.84000015258789}],"_msgid":"8a25a7a58e2fcf26"}
Just trying to calculate the current given the power and voltage values.
Didn’t think it was going to take me 8 hours how to figure out how to divide 2 numbers, but it has..
The 1st value is my power(W) and the 2nd is the voltage(V).
1st value path: payload[0].value
2nd value path: payload[1].value
Can anyone give me any idea how to pull this off? I must have tried every possible way, how not to solve it.
Be easy on me, didn’t even know what Node-RED was until 4 days ago. Add to that, never written a single line of JavaScript EVER 🙂 Made it this far, then just slammed into a brick wall.
Thanks all!
Everything, except the way to do it correctly…
Craig Belcher is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.