Writing array of arrays data to Influx

I'm a bit of a novice but have made progress on my Node-Red skills but I have one last hurdle I can't quite figure out. I have an IOT node that takes temperature readings every X amount of time, stores it and then after Y amount of time sends all the data as a Hex string to my node-red (current reading + 8 historical readings). I have a Javascript that parses the hex string and puts the values into an array. Each data set is an array as well (is that right?) An array of arrays? The data set is Hive, Temp & Time, repeated. I need to write each data set within the array to my Influx DB. (Hive is the tag)

Here is what the output of the Javascript function is.

image

I have the Influx database out node, which I'm using on other flows successfully.
image

Would someone be kinda enough to nudge me in the write direction?

On another flow, that only has a single reading, I use a Change node that looks like this.

[
    {
        "TempLower": payload.TempLower,
        "time": payload.time
    },{
        "hive": payload.hive
    }
]

Not sure that it helps but this is my InfluxDB measurement table.

select * from S31B
name: S31B
time Humidity TempLower hive


1703981797 42.7 71.06 f866207058384979
1703982397 42 71.6 f866207058384979
1703982697 41.7 71.78 f866207058384979

Welcome to the forum @NewHopeFarm

Why don't you send each value as it is received, rather than saving them up?

You need to make an array of arrays, where each element is as you have shown for your single reading, with the addition of a time field which must contain the time value in (I think) the units specified for Time Precision (default is millisecs). So for the example you show it should be an array of 7 objects, where each element is an array of 2 objects, the first being the fields and the second being the tags. So each of the 7 elements will be something like

[
    {
        "TempLower": 42.7,
        "time": 1703982697000
    },{
        "hive": "f866207058384979"
    }
]

The example you show has the time as a string, it must be a number, and it looks like nanosecs, whereas I am pretty sure it should be msec as that is how you have configured the precision. I am not certain about that though as it may also be down to the database settings. If the times come out all wrong try nanosecs. Oddly the other example you show
1703981797 42.7 71.06 f866207058384979
appears to be in seconds.

Thanks Colin for the reply!

Why don't you send each value as it is received, rather than saving them up?

The device is a cellular device and as a battery saving mechanism, it wakes up long enough to take a temperature reading, store the data, go back into sleep mode. Then every so often it does a batch upload of the data. This allows me to take frequent temperature readings without killing the battery to make a cellular connection.

So for the example you show it should be an array of 7 objects, where each element is an array of 2 objects, the first being the fields and the second being the tags.

I think that is where I am struggling, is how to create an array with two objects. Is there any sample javascript code that would demonstrate that?

Here is a snippet of code that is creating the array:

var imei = 12345678910
var array=[]
var bytes="0x"
for (var i=1;i<data1.length;i++){ //Loop through array to get data
    var temperature=((parseInt(bytes+data1[i].substring(4,8))/10)*9/5)+32  // 4,5,6,7 
    var time1=parseInt(bytes+data1[i].substring(16,)) // 16 until end
    var obj={
        'hive':imei,
        'TempLower':temperature,
        'time':time1+'000000000'
    }
    array[i]=obj
}
msg.payload=[array]

am pretty sure it should be msec as that is how you have configured the precision.

Yea, I'm adding 0's so that InfluxDB doesn't complain. I probably didn't configure the InfluxDB correctly. It works for now. If I can get the data written, I can see about fixing time precision.

Matthew

Thanks Colin. Your guidance got me in the right direction and it is working now. After creating the array of array with 2 objects and then feeding that into a SPLIT function, it is working!!

Here is how I split it into 2 objects.

    var obj=[{
        'TempLower':ds18b201,
        'time':time1+'000000000'},
    {
        'hive':imei,
    }]
    array[i]=obj
}

Change that to
msg.payload=array
and remove the split node.

Thanks! I couldn't figure out why I had 3 layers of arrays.