# Post data to influxdb 1.x with own timestamp

**URL:** <https://discourse.nodered.org/t/post-data-to-influxdb-1-x-with-own-timestamp/81090>\
**Category:** General\
**Created:** [7 September 2023 06:45 UTC](https://discourse.nodered.org/t/post-data-to-influxdb-1-x-with-own-timestamp/81090 "2023-09-07T06:45:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [7 September 2023 06:45 UTC](https://discourse.nodered.org/t/post-data-to-influxdb-1-x-with-own-timestamp/81090/1 "2023-09-07T06:45:41Z")

</div>

I need to post data to InfluxDB with its original timestamp since the data may arrive at the database at a different time from when it was generated. I'm encountering difficulties!  
The influx version is still the 1.x

This is the typical payload I receive:  
`payload: "113|25.75|2023-09-07T06:32:28.434Z"`  
The last portion is the timestamp at the time the measurements taken.

This is the output of the function receiving the above payload:

 ![Screenshot 2023-09-07 at 08.36.03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/0674fda4683b478de8f0393466c43495933dc243.png)

This is the function I wrote:

```auto
if (msg.topic === "BMS!2022/temperature") {
    var t = msg.payload;

    // Find the last occurrence of a pipe, which should be the start of the timestamp
    var lastPipeIndex = t.lastIndexOf('|');

    // Extract DeviceID and temperature
    var DeviceID = t.substring(0, t.indexOf('|'));
    var Tamb = parseFloat(t.substring(t.indexOf('|') + 1, lastPipeIndex));

    // Extract the RFC 3339 timestamp
    var rfc3339Timestamp = t.substring(lastPipeIndex + 1);

    // Convert RFC 3339 timestamp to nanoseconds
    var date = new Date(rfc3339Timestamp);
    var nanoTimestamp = date.getTime() * 1e6; // Convert milliseconds to nanoseconds

    msg.topic = "temperature";

    if (DeviceID && !isNaN(Tamb)) {
        msg.payload = {
            "Tamb": Tamb,
            "timestamp": nanoTimestamp // Use nanosecond precision timestamp
        };
        msg.measurement = DeviceID;
        msg.timestamp = nanoTimestamp;
        return msg;
    }
} else {

    return null;
}

```

and this is the content of the measurement in influx:

```auto
time Tamb timestamp
---- ---- ---------
1694064087553806889 22.312 1694064087550000000
1694064117590312070 22.312 1694064117586000000
1694064147639415844 22.312 1694064147614000000

```

based on what I see in the above influx output, the db is still using its own time stamp rather then the one I provide. This is also confirmed by showing the data on a chart.  
I need some help to make sure that influx use the provided timestamp instead of the own one.

---

<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:** [7 September 2023 07:06 UTC](https://discourse.nodered.org/t/post-data-to-influxdb-1-x-with-own-timestamp/81090/2 "2023-09-07T07:06:04Z")

</div>

Try making it `time` in the payload instead of `timestamp`.

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [7 September 2023 07:44 UTC](https://discourse.nodered.org/t/post-data-to-influxdb-1-x-with-own-timestamp/81090/3 "2023-09-07T07:44:33Z")

</div>

Hi Colin. You are a star! Thanks a million. It works well now.

---

<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:** [21 September 2023 07:44 UTC](https://discourse.nodered.org/t/post-data-to-influxdb-1-x-with-own-timestamp/81090/4 "2023-09-21T07:44:35Z")

</div>

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