Retrieve values from payload object

Hi all,

New to node-red here, and looking to store some IoT data coming from TTN into a postgres database.
I am having a hard time formatting the data.
Here is the payload I receive

4/21/2023, 1:19:29 AM[node: msg.payload](http://xx.xxx.xx.xxx:1880/#)v3/xxxxx@sxxxx/devices/eui-x/up : msg.payload : Object

object

Bat: 3.354

TempC_DS18B20: "0.0"

conduct_SOIL: 89

temp_SOIL: "21.04"

water_SOIL: "22.02"`

Here is the function I use to format the data :

msg.payload = {
        timestamp_data: new Date(),
        device_battery: parseFloat(msg.payload.Bat),
        soil_conductivity: parseInt(msg.payload.conduct_SOIL),
        soil_temperature: parseFloat(msg.payload.temp_SOIL),
        soil_humidity: parseFloat(msg.payload.water_SOIL)
        
        
        
    };
return msg;

But when I do this here is what I receive :

4/21/2023, 1:33:24 AM[node: msg.payload](http://xx.xxx.xx.xxx:1880/#)v3/xxxxx@sowit/devices/eui-x/up : msg.payload : Object

{ timestamp_data: "2023-04-21T01:33:23.953Z", device_battery: NaN, soil_conductivity: NaN, soil_temperature: NaN, soil_humidity: NaN }

I don't understand why I get NaN instead of the values, happy to get your insights.

Thanks,
HB

Can you put a debug node on and let us see the output of the data that you are getting returned back from the API call ?

That would make it easier to understand what us happening

Craig

MODERATOR NOTE: I have edited your post and removed the IP address you included as your NR site is accessible from the internet.

THIS IS DANGEROUS AND YOU OPEN YOURSELF TO BEING HACKED.

I would recommend you take steps to secure your site before you do anything else!

Hi @zenofmud thank you for the initiative, point taken.

best regards,
HB

Add a debug node to the output of all the mqtt-in nodes to show the data each function node is getting. Then copy/paste the debug's msg.payload in a response.

Is that the debug output of the mqtt-in node that feeds the function node with the issue?

You are trying to access msg.payload.Bat but the value for "Bat" is msg.payload.uplink_message.decoded_payload.Bat.

I discovered this using the "Copy path" button on the debug panel.

Thanks @jbudd solved the issue

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