# Four InfluxDB node (data is very confusing and not unique)

**URL:** https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466
**Category:** General
**Created:** [29 November 2022 16:09 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466 "2022-11-29T16:09:22Z")
**Posts on this page:** 13
**Page:** 2

<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: [6 December 2022 15:34 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/22 "2022-12-06T15:34:19Z")

</div>

> [@lihao](#):
>
> The key to my question should be that the influxDB abscissa should be in units of data points, not time intervals.

Influxdb is a time series database, you have to provide a time if you want to use Influx.

> [@lihao](#):
>
> I collect data through Bluetooth, and then use the serial port to transmit to node red

Can you add a timestamp before you send it to node-red?  
And while you are at it send the data as a json string.

---

<div class="post-metadata">

### Author: ![lihao](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lihao/32/72171_2.png) [@lihao](https://discourse.nodered.org/u/lihao)
#### Post date: [7 December 2022 07:28 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/23 "2022-12-07T07:28:38Z")

</div>

> [@Colin](#):
>
> Influxdb is a time series database, you have to provide a time if you want to use Influx.

Thanks Colin.  
Yes, I'm looking at whether grafana can use the number of data points as the x-axis instead of time as the x-axis. But I haven't found a solution yet, do you have any suggestions?

> [@Colin](#):
>
> Can you add a timestamp before you send it to node-red?  
> And while you are at it send the data as a json string.

I really don't know how to convert the data to json before entering node red?  
I receive data via bluetooth, and then output to node red through the serial port. The Bluetooth interval is about 10ms, 10 samples are transmitted each time, 100 times per second (exactly 1000 samples in total), and the data sampling rate is 1kSPS. Can I receive data through Bluetooth and give each sample a time stamp, just like new Date()-i (i from 0 to 9) ten times a cycle corresponds to bluetooth passing 10 times of sampling data each time.

---

<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 December 2022 10:05 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/24 "2022-12-07T10:05:10Z")

</div>

> [@lihao](#):
>
> I really don't know how to convert the data to json before entering node red?

Instead of sending the string  
`7.5, 23.2, 5.0, 27`  
send the string  
`{"ch1": 7.5, "ch2": 23.2, "ch3":5.0, "ch4": 27}`  
Then you can read that whole string in the serial node and feed it directly into a JSON node which will convert it directly to a javascript object ready for adding into the message to be sent to Influx.

> [@lihao](#):
>
> Can I receive data through Bluetooth and give each sample a time stamp

It depends on what device you are doing that on, and whether it knows the current time.

---

<div class="post-metadata">

### Author: ![lihao](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lihao/32/72171_2.png) [@lihao](https://discourse.nodered.org/u/lihao)
#### Post date: [7 December 2022 13:09 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/25 "2022-12-07T13:09:09Z")

</div>

My sampling rate is 1000 times per second, and the sampling interval of each of the four channel data is 1ms. Because of the Bluetooth transmission problem, I need to send ten sampling values ​​to the host computer, and then to node red through the serial port. The ten sampling values ​​are in the same ms, which is the key to my problem.  
Thank you for adding a timestamp reminder before entering node red. My idea is to return the current system tick value (get\_HALtick) for each sample before Bluetooth transmission, which is how long the system has been running in ms, and then combine it with node red. Form a timestamp (but I don't know how to combine my timestamp, because using new data() will introduce the time of Bluetooth transmission).

In fact, what I want is that the time difference of each array is 1ms. I think this can be realized in node red. For example, the timestamp of the first array[1000] is from 1ms to 1000ms, and the timestamp of the second array[1000] is from 1001ms to 2000ms and then keep going...（  
I think this is more feasible） 😂  
But I don't know how to code it...

Thanks again.

---

<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 December 2022 13:32 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/26 "2022-12-07T13:32:33Z")

</div>

If you start with a known time in a variable called lastTime, then you can add 1 millisecond to that using  
`const nextTime = new Date( lastTime .getTime() + 1)`  
or if you have startTime and want to add n milliseconds to it then  
`const thisTime = new Date(startTime.getTime() + n)`

---

<div class="post-metadata">

### Author: ![lihao](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lihao/32/72171_2.png) [@lihao](https://discourse.nodered.org/u/lihao)
#### Post date: [7 December 2022 14:22 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/27 "2022-12-07T14:22:51Z")

</div>

![3f7cda604435cb51d2c74cf46d13f7e](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78c408bff6020622f1275da87cfed5158994bb26.png)  
Sorry, maybe I misexpressed. What I mean is that there is a variable i with an initial value of 0. Every time the function marked in the red circle is executed, i+1 has nothing to do with the time that has passed. For example, the value of i is 1000 when this function is executed for the 1000th time.

---

<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 December 2022 14:43 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/28 "2022-12-07T14:43:58Z")

</div>

In that case all you need to do is to add one to it each time. In a function node

```auto
let count = context.get("count") || 0
count = count +1
context.set("count", count)
msg.payload = count
return msg

```

I don't see what good that is going to do you though

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b6c127b24bbdd3fd9197c91e8da16f499da7690.png)

```auto
[{"id":"b0d5b0b4b0ccc0c0","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":3120,"wires":[["23e195269765726a"]]},{"id":"23e195269765726a","type":"function","z":"bdd7be38.d3b55","name":"Counter","func":"let count = context.get(\"count\") || 0\ncount = count + 1\ncontext.set(\"count\", count)\nmsg.payload = count\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":3120,"wires":[["45f5d379f8b9c733"]]},{"id":"45f5d379f8b9c733","type":"debug","z":"bdd7be38.d3b55","name":"debug 65","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":460,"y":3120,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![lihao](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lihao/32/72171_2.png) [@lihao](https://discourse.nodered.org/u/lihao)
#### Post date: [7 December 2022 16:18 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/32 "2022-12-07T16:18:16Z")

</div>

My expression is wrong here. What I want to say is that I transmit an array of 1000 elements per second, and the element timestamp interval is 1ms. I don’t know why influxDB only has data at the beginning, and then no data

---

<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 December 2022 16:43 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/34 "2022-12-07T16:43:40Z")

</div>

Do you mean that you pass one seconds worth of data into influx, with timestamps from 0 to 1000 milliseconds, then you do the same thing again (with timestamps 0 1000 again? If so then you will just keep overwriting that 1 seconds worth of information. Timestamps from 0 to 1000 are effectively the first second of the year 1970.

---

<div class="post-metadata">

### Author: ![lihao](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lihao/32/72171_2.png) [@lihao](https://discourse.nodered.org/u/lihao)
#### Post date: [7 December 2022 17:23 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/35 "2022-12-07T17:23:48Z")

</div>

I really didn't pay attention to whether 0ms to 1000ms are repeated, but I remember that it can be added all the time. For example, the first array is 0 to 999ms, and the second array is 1000 to 1999ms. Another point is that if the data is overwritten, the data should be displayed repeatedly in the last second, but no data will be displayed when I refresh. In fact, the data initially displayed will change over time, such as the second minute, the fifth minute, and so on. Is there any problem if I give time stamps manually?

---

<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 December 2022 18:02 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/36 "2022-12-07T18:02:39Z")

</div>

Send the data going into influx into a debug node and show us what you get for two consecutive messages. Expand enough of the start of each message so we can see what is there. Also show us what you see in grafana

---

<div class="post-metadata">

### Author: ![lihao](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lihao/32/72171_2.png) [@lihao](https://discourse.nodered.org/u/lihao)
#### Post date: [8 December 2022 02:38 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/37 "2022-12-08T02:38:14Z")

</div>

I tried it again this morning and I see that I have succeeded. Although I don't know what caused my problem last night.  
I really appreciate your help and the platform node red

 ![5c837b5f53c606a027984351740f20a](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da1cc0f8f4bee5fa6c11a95c85b9cd99e51f7d3d.png)

---

<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: [22 December 2022 02:38 UTC](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466/38 "2022-12-22T02:38:50Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/four-influxdb-node-data-is-very-confusing-and-not-unique/71466.md?page=1)
