Writing specific data from parsed json object into influxdb 1.8x

Dears

I am calling data from my fronius inverter via a http request node (solar api) and receive a parsed json object:

I am interested into writing "P_GRID" into the measurement "P_GRID" into field "default"
in this case the value 496,8

so far I was able to get this data into an object with this function:

msg.payload = [
{measurement: "P_PV2",
fields: {
P_Grid: msg.payload.Body.Data.Site.P_Grid,
},},]
return msg;

resulting in:
grafik

from here i am unable to write the number (!) 496,8 into the field "default" of measurement "energy"

I think i need to convert 496,8 into a number and then have a function node write this number into the correct measurement and field

any help is greatly appreciated :slight_smile:

Try

msg.payload = [{
  measurement: "P_PV2",
  fields: {
    P_Grid:  +msg.payload.Body.Data.Site.P_Grid,
  }
}]
1 Like

thanks!
I did as you suggested:

msg.payload = [{
measurement: "P_Grid Stromverbrauch",
fields: {
default: +msg.payload.Body.Data.Site.P_Grid,
}
}]
return msg

If I don't specify a measurement in my influxdb node I get:
grafik
I expected the measurement to be specified in the function above

If i do specify "P_Grid Stromverbrauch" in the influxdb node as measurement I get:

In the help text for the influx Out node it these options for what you need in msg.payload:

If msg.payload is an object containing multiple properties, the fields will be written to the measurement.
If msg.payload is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags.
Finally, if msg.payload is an array of arrays, it will be written as a series of points containing fields and tags.

Your payload is an array of one object so does meet any of those.
Also it says that to pass the measurement the message you should use msg.measurement.

If you want to write the value into the field "default", which seems strange, then you need msg.payload just to contain
{default: 496.8}
and you need msg.measurement to contain the measurement name. Note that the value 496.8 must be a number not a string. You can use that by saying something like
msg.payload = {default: Number(msg.payload.Body.Data.Site.P_Grid)}

Normally the field would either be something like "P_GRID" or "value".

i am looking into this, tnx!
the name "default" is strange indeed, but i am referring to an existing database, which i didn't set up

it is working :slight_smile:
here is the working function:

msg.measurement = "P_PV2";
msg.payload = [{
P_Grid: Number(msg.payload.Body.Data.Site.P_Grid)
},
{}];
return msg;

I parsed correctly for the desired value "P_Grid"
I converted P_Grid into a number
I am writing to measurement "P_PV2"

tnx to all of you for your help

Since there are not any tags you should be able to use just

msg.measurement = "P_PV2";
msg.payload = {
  P_Grid: Number(msg.payload.Body.Data.Site.P_Grid)
}
return msg;
1 Like

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