How to only pass through a certain part of an array?

Hi

I have a node sending data from a energy-meter.
The data that i recieve is delivered like this.
Delivery 1: an array of data,
Delivery 2. a given value (1 line of the array)
Delivery 3: a given value (1 line of the array)

I am using a function node to extract a certain value frome the array:

var o = msg.payload
msg.payload = o.volt_L3 / 10
return msg;

The issue is sthat "delivery nr 2 & 3" does not have the array, therfore the results is "NaN".

The value i try to extract is passed on to a smart-house-system. The "NaN" value is therfore translated in to "0" in the smart-house-system.

What is best-pracsis for only extracting data from the msg. that has the full array, and skipp/not pass on the data from the msg. that doesnt have the full array.

That will not work if msg.payload is an array. Perhaps you mean a javascript object. I think you had better feed the messages into a debug node and show us what you have actually got.

What node are you using for getting the data?

Are your values coming into the function from separate wires? You might need a join node

Show us your flow.

You can filter your payload with a switch node, checking if the payload contains an array.

image

Hi

This is the debug frome the node ( AMD decoder)

As you can see from the picture, every 3. messages is the "whole object", the 2 other messages contains onlye the vale "act_pow_pos"

Its all beeing "picked upp" trough a USB-adapter..

Ok then it is not an array which you need to pick out - so you need to filter on a specific property.

[{"id":"3f247e651403fc6f","type":"switch","z":"cb05e14b.326a9","name":"","property":"payload.meter_ID","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":620,"y":1580,"wires":[[]]}]

So only those messages will pass with a valid meter_ID

Maybe i was a bit unclear.. in my example i would like to only extra the value corresponding to: volt_L1.
If i use a change node to "extract" the value, the messeages that dosent have the value for volt_L1 returnes as "undefined".

image

OK - then use the switch - I posted before and check for payload.volt_L1 not null.

Yes, sorry. This solves it.
image

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.