Reputation: 73
I have multiple Modbus variables that I am trying to store on my local disk.
My function script is as follows:
var msgPortBus,msgStbdBus;
if (msg.topic === 'BusVolts') {
msgPortBus = { payload: msg.payload.Port.Bus.Volts, };
msgStbdBus = { payload: msg.payload.STBD.Bus.Volts, };
}
msg.payload = [msgPortBus,msgStbdBus]
return msg;
I assume the error is in the code above somewhere.... The topics for both Modbus nodes are 'BusVolts'.
I had used the following code for one input, which gives me my timestamp and then the data I would like from one input, but I was not sure how to differentiate between different payloads.
msg.payload = new Date().toString() +
"," + msg.payload;
return msg;
Thanks in advance.
EDIT: Error is "Type Error: Cannot read property 'Bus' of undefined"
Upvotes: 0
Views: 1508
Reputation: 59751
The problem is that you are assuming that the when the function node runs it will see a combined msg
object that contains the information from both modbus nodes. This is not the case.
The function node will run separately for each output message from the modbus nodes, so only one of the msg.payload.Port.Bus.Volts
or msg.payload.STBD.Bus.Volts
will be populated at a time.
If you want to combine the output of multiple nodes before feeding it into the function node you will need to look at either storing data in the Context or using the Join node to batch the outputs together into an array before processing it.
Upvotes: 2