# Time problem with a group of messages

**URL:** <https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065>\
**Category:** General\
**Created:** [9 July 2019 09:01 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065 "2019-07-09T09:01:41Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [9 July 2019 09:01 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/1 "2019-07-09T09:01:42Z")

</div>

Hello, I'm requesting your help, my sensor send me actually a packet of 3 messages in 1 message with 3 measurements, 1 every X minutes. My payload contains the time beetween 2 measurements. I know that I can split it in 3 messages but I don't know how to manage the time stamp to display it.  
I'm using InfluxDB to store my data and then to display it on grafana.  
(sorry for my English, if something is not clear please tell me)

Thank you,

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 July 2019 09:52 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/2 "2019-07-09T09:52:21Z")

</div>

use a `change` node to set msg.sensor\_timestamp to the timestamp variable. Then send the output to a split node. Each new msg will include in msg.sensor\_timestamp the original value.

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [10 July 2019 11:11 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/3 "2019-07-10T11:11:08Z")

</div>

Thank for your reply but i do not understand it, I should convert my timestamp to my variable like 15 minutes (wich means on measurement every 15 minutes) ? And then split this message in 3 messages ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 July 2019 16:01 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/4 "2019-07-10T16:01:40Z")

</div>

As I understand you, your message comes in containing three peices of data and a time measurement.

If you want three msgs, each containing the time measurement, then use the `change` node to add a new field to the msg object. You can call it anything, but for this example let us say it is msg.time\_between. In the `change` node to copy the _time between 2 measurements_ to msg.time\_between. Then you will have your msg with the treee measurements AND a new piece of the msg: msg.time\_betrween.

It would be easer to explain if you showed a debug of your data coming in.

Now when you split the msg into three messages, each one will contain msg.time\_between.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 July 2019 17:16 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/5 "2019-07-10T17:16:45Z")

</div>

Can you post an example debug output ?

---

<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:** [10 July 2019 20:29 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/6 "2019-07-10T20:29:25Z")

</div>

Also explain again exactly what you are trying to do.

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [11 July 2019 09:12 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/7 "2019-07-11T09:12:19Z")

</div>

Ok sorry I think I was not clear, I'm sorry. I will try to explain you my aim: To save energy my device is sending a message only one time X hours, every message contains not one but 3 measurements and one information about the time measurements (X) and also only one time stamp. What I have to do is to split my message in 3 messages, each one will contain 1 measurement and one time\_stamp.  
Per example: if I received one message at 11AM with the info that X=1 hour it's mean that I need to split in 3 messages: the first with a time\_stamp equals to 9AM, the other one 10 AM and the last one 11AM.  
Thank you for your help

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 July 2019 09:46 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/8 "2019-07-11T09:46:10Z")

</div>

Can you show us what the debug output looks like of a single message with the 3 measurements ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 July 2019 12:45 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/9 "2019-07-11T12:45:57Z")

</div>

So the time for

- the first measurement is `current time` - (2 x X) hours
- the second measurement is `current time` - (1 x X) hours
- the third measurement is `current time`

So you should split the original message into the three parts, then use a switch to send the three parts to different paths - the path for the first measurement will use a change node to set the time to now - 2 hour. In the change node use the jsonata option with the code `$milli()-7200000`

1. [`$millis()`](https://docs.jsonata.org/date-time-functions#millis) returns the timestamp as the number of milliseconds since midnight on 1st January 1970 UTC (the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time)).
2. Two hour = 7,200,000 milliseconds

ou should be able to figure out the rest

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [11 July 2019 14:45 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/10 "2019-07-11T14:45:11Z")

</div>

I dont" what to show you it's like a regulard payload with 14 hex with 2 hex for each temperature (so 6 hex) and one hex for the time beetween measurements.

Oh thank you for your solution, I'm going to do that, I need then to store this data in influxDB, and to display it in Grafana. How can I manage this difference of time to see a chart with my 3 data with X hours of difference beetween each measurements ?  
Thank you for your replies

---

<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:** [11 July 2019 15:58 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/11 "2019-07-11T15:58:22Z")

</div>

The problem is not an influx to grafana issue, but making sure that when you write the data to influx you write the correct timestamps for each sample. You must take @zenofmud's advice and split the data into three values each with the adjusted timestamp and put that into influx. Then Grafana will show it correctly.

---

<div class="post-metadata">

**Author:** ![eng56](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@eng56](https://discourse.nodered.org/u/eng56)\
**Post date:** [15 July 2019 13:18 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/12 "2019-07-15T13:18:33Z")

</div>

First sorry for my late reply, now I have successed to split in 3 different messages with 3 different payloads, last question: how to inject in influxdb my timestamps ? Actually (and it's working) my paylod is an array with [0]= fields and [1]= tags so where do I have to put my time stamp ?  
This is what i am currently injecting in InfluxDB:  
Thank you  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d30d06e057e0a2605cac7d542c4ac0a2a53ad95e.png)

---

<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:** [15 July 2019 19:27 UTC](https://discourse.nodered.org/t/time-problem-with-a-group-of-messages/13065/13 "2019-07-15T19:27:48Z")

</div>

I think you have to use the influxdb batch node for this.
