Turning an array of acceleration values into individual records for influxdb

Hi there!

I am using Node-RED to take incoming MQTT msgs every second that contain values from an accelerometer. Each msg has an array of JSON objects that contain x,y,z arrays of 32 floats, as well as the device id. A sample msg with one second of accelerometer data may look like this:


I'm having trouble writing a function node that separate these values into 32 separate entries that can be written to an influxdb out node, where each entry would look something like:

traces,device_id=A8032A4DD5F0 x=-0.03 y=1.02 z=-3.23 1465839830100400200
(timestamp is created by influx on arrival)

Given that the accelerations have been buffered on the device for one second, each of the 32 array is actually 1/32s.

The difficulty im having is setting the time for each entry so that the first x,y,z is 32/32s, the next is 31/32s, then 30/32s etc.

Im not sure if that makes sense! please let me know any pointers.

Thank you,

Since you don't send the timestamp from the device you will need to use (Date.now()-1000) as your first record then add 31.25 to each one in the loop that generates your payloads.

Note, because you don't send timestamp from source, you are likely to see deviation in the timestamps between sets of data due to network latency.

1 Like

That makes sense. Thank you! I will try now :grinning:

You have not said, but you should use the influxdb batch node for this so they are all written in one go.

1 Like

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