# Turning an array of acceleration values into individual records for influxdb

**URL:** <https://discourse.nodered.org/t/turning-an-array-of-acceleration-values-into-individual-records-for-influxdb/41871>\
**Category:** General\
**Created:** [2 March 2021 05:12 UTC](https://discourse.nodered.org/t/turning-an-array-of-acceleration-values-into-individual-records-for-influxdb/41871 "2021-03-02T05:12:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seismo](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@seismo](https://discourse.nodered.org/u/seismo)\
**Post date:** [2 March 2021 05:12 UTC](https://discourse.nodered.org/t/turning-an-array-of-acceleration-values-into-individual-records-for-influxdb/41871/1 "2021-03-02T05:12:49Z")

</div>

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:

`{"d":{"device_id":"A8032A4DD5F0","traces":[{"x":[-0.03,-0.011,-0.019,0,-0.026,-0.023,0.091,-0.049,0.004,0.03,-0.023,-0.004,0.057,0.049,0.023,-0.008,-0.113,0.008,-0.026,-0.023,0.015,-0.026,-0.004,0,0.011,-0.045,0.004,-0.008,-0.124,-0.026,0.041,0],"y":[-0.207,-0.083,-0.147,-0.298,-0.253,-0.256,-0.158,-0.17,-0.147,-0.275,-0.287,-0.207,-0.26,-0.162,-0.241,-0.215,-0.162,-0.223,-0.207,-0.207,-0.219,-0.264,-0.26,-0.226,-0.215,-0.162,-0.181,-0.181,-0.207,-0.256,-0.162,-0.155],"z":[-0.17,-0.204,-0.2,0.011,-0.249,-0.17,-0.057,-0.204,-0.106,0.038,-0.17,-0.196,-0.185,-0.256,-0.079,-0.068,-0.072,-0.128,-0.136,-0.102,-0.091,-0.049,-0.109,-0.143,-0.038,-0.279,-0.147,-0.109,-0.004,-0.151,-0.26,-0.162]}]}}`

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,

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 March 2021 06:13 UTC](https://discourse.nodered.org/t/turning-an-array-of-acceleration-values-into-individual-records-for-influxdb/41871/2 "2021-03-02T06:13:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![seismo](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@seismo](https://discourse.nodered.org/u/seismo)\
**Post date:** [2 March 2021 06:17 UTC](https://discourse.nodered.org/t/turning-an-array-of-acceleration-values-into-individual-records-for-influxdb/41871/3 "2021-03-02T06:17:21Z")

</div>

That makes sense. Thank you! I will try now 😀

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 March 2021 08:09 UTC](https://discourse.nodered.org/t/turning-an-array-of-acceleration-values-into-individual-records-for-influxdb/41871/4 "2021-03-02T08:09:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 May 2021 08:10 UTC](https://discourse.nodered.org/t/turning-an-array-of-acceleration-values-into-individual-records-for-influxdb/41871/5 "2021-05-01T08:10:07Z")

</div>

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