Write nested JSON data to influxdb

Hello.
I’m trying to store the battery data that is captured every second in a Influxdb database. The battery can have a number of cells ranging from 0 to 256, which have their own parameters. I managed to create a flow in Node RED that boils down to the object that looks like this:

{
  "topic": "InputData",
  "payload": "Bms 13",
  "ip": "::ffff:192.168.1.111",
  "port": 3755,
  "_session": {
    "type": "tcp",
    "id": "199dd01a.f1d44"
  },
  "_msgid": "39ce8762.80f7f8",
  "IsBmsState": true,
  "BmsInfo": {
    "State": 13,
    "CellInfos": {
      "0": {
        "Num": 0,
        "Voltage": 4.043,
        "Temp": 53,
        "TempBal": 19,
        "CellTemp": 6
      },
      "1": {
        "Num": 1,
        "Voltage": 4.088,
        "Temp": 24.2,
        "TempBal": 19,
        "CellTemp": 6
      },
      "2": {
        "Num": 2,
        "Voltage": 4.073,
        "Temp": 19.3,
        "TempBal": 19,
        "CellTemp": 6
      },
      "3": {
        "Num": 3,
        "Voltage": 4.052,
        "Temp": 15,
        "TempBal": 19,
        "CellTemp": 6
      },
      "length": 4
    }
  }
}

This represents a single measurement from the battery. Now I need to store it in the database. And this is where I need your help. After googling around I found out that it’s not possible to store nested JSON object in Influxdb and I’m currently out of ideas how this can be done.
What would be the appropriate schema design for this?
I’m sure there is the right way to do it, but i’m completely new to the time series databases and databases in general.
Any help is really appreciated.

Hi @influsk,

So, when I design schemas I like to imagine the types of math operations over groups of data I’d like to do.
(here are the influxql math functions: InfluxQL functions | InfluxDB OSS 1.7 Documentation)

I’m going to hazard a guess about what you would like to do, BUT, here are a few possible queries:

  • max of all cell temperatures per battery over time
  • mean of all cell temperatures per battery over time
  • min of all cell voltages per battery over time
  • mean of all cell temperatures for ALL batteries over time
  • rate of change of mean of all cell voltage for ALL batteries

In InfluxQL to create queries like those you need to create “tags” for grouping. So, for those types of queries, I would have 2 tags: battery id, cell id; and 4 fields: voltage, temp, temp_bal, cell_temp. I want to group by battery and/or cell id and run math functions such as mean or max over the some of the fields in those groups.

For all the rest of the data in your JSON to tell if it should be a field or a tag imagine if you need to group by them as my example query ideas grouped by cell and battery. For example, do you imagine needing to do the mean of voltage of all ip addresses? If so, you would add ip addresses as a tag.

1 Like

Has there been an update on handling nested data with InfluxDB directly without flattening? Has there been a new development with Influx 2.0 out?

Thanks,
Deepak

Hello @deepaksurana18,
Welcome! Have you tried using any of the following?

https://flows.nodered.org/collection/grRlwGjSt-Ae