The node that 1st message came from is different to the 2 below
However, as you say, it is always good practice to check the type (as many nodes will send empty or odd results upon failure).
To be follow up to your reply, something like below would be another belt + brace...
if( Array.isArray(msg.payload) && msg.payload.length ) {
msg.payload = msg.payload[0].toString();
return msg;
}else{
node.error("msg.payload is not a valid array", msg); //always include the msg so that the catch node can catch the error
}
Yes, so I can check the direct output of the Modbus connector. This is how the function looks now
if( Array.isArray(msg.payload) && msg.payload.length ) {
msg.payload = msg.payload[0].toString();
return msg;
}else{
node.error("msg.payload is not a valid array", msg); //always include the msg so that the catch node can catch the error
}
Gives now the error that the array is not valid. I have really no clue what is happening, because if I output directly the modus to the msg payload the debug window says it's a array
Leave the function node attached & add a 2nd debug node. Connect that to the same output that the function node is connected to on the modbus node (i.e. 2 wires from same output pin, 1 already going to function, other going to the newly added debug node) - what do you see.
I suspect you are using a different modbus output pin to monitor the debug output to what you connect the function (hint, the 2 outputs of the modbus output different objects- you can verify that by having 2 debugs, 1 on each output of the modbus node)