Data written with correct timestamp does not get visualized in Chronograf InfluxDB

619 views Asked by At

I have an embedded board which sends information from IMU sensors along with a timestamp received from a RTC Module.

The Timestamps are obtained from Adafruit's RTClib

The code has a function called unixtime() which provides me timestamps as follows:

1537466106 
1537466107
1537466109

If I enter the above mentioned timestamps in Online Epoch Converter, it provides me the correct time as of today.

I send this information via HTTP and the information gets stored in InfluxDB under imu measurement as follows:

Query: SELECT * FROM imu LIMIT 100

time       eul_x  eul_y  eul_z  liac_x liac_y liac_z location nodeid status
----       -----  -----  -----  ------ ------ ------ -------- ------ ------
1537466106 273.25 -0.88  4.06   -0.06  -0.74  9.81   front    node1  0
1537466107 273.25 -0.88  4.12   -0.09  -0.87  9.72   front    node1  0
1537466109 273.25 -0.88  4.12   -0.09  -0.86  9.62   front    node1  0
1537466110 273.25 -0.88  4.12   -0.07  -0.84  9.67   front    node1  0
1537466111 273.25 -0.88  4.12   -0.1   -0.85  9.71   front    node1  0
1537466112 273.25 -0.88  4.12   -0.08  -0.86  9.74   front    node1  0
1537466113 273.25 -0.88  4.12   -0.04  -0.83  9.7    front    node1  0
1537466114 273.25 -0.88  4.12   -0.07  -0.84  9.7    front    node1  0
1537466115 273.25 -0.88  4.12   -0.07  -0.85  9.67   front    node1  0
1537466116 273.25 -0.88  4.12   -0.06  -0.85  9.67   front    node1  0
1537466117 273.25 -0.88  4.12   -0.06  -0.84  9.66   front    node1  0
1537466118 273.25 -0.88  4.12   -0.07  -0.83  9.66   front    node1  0
1537466119 273.25 -0.88  4.12   -0.09  -0.83  9.68   front    node1  0
1537466120 273.25 -0.88  4.12   -0.08  -0.84  9.7    front    node1  0
1537466121 273.25 -0.81  4.12   -0.08  -0.87  9.52   front    node1  0
1537466123 272.12 -0.81  -3.06  -0.15  0.54   9.74   front    node1  0

Now I run an Chronograf Instance on the machine to visualize the data obtained in the above mentioned measurement

Chronograf Query

Chronograf Query

Strangely the table always keeps showing that the timestamps are point to the Epoch of 1970

Table shows wrong timestamps

Querying a single field from the Database provides the following output:

Query is correct but no result

Research

I read the documents for InfluxDB and they have timestamps for nanoseconds precision.

On the contrary the timestamps I mentioned above are in fact, correct but why can Chronograf/ InfluxDB not grasp it correctly?

case

I obtain the timestamps as uint32_t from the RTClib but I am not sure how do I convert it to nanoseconds precision.

I am sending the timestamp information as a string, is it wise to concat zeros to the string? If So how many zeroes might be required?

1

There are 1 answers

0
Shan-Desai On BEST ANSWER

Hardware

I am using the DS3231 RTC module which provides a precision of seconds. [1].

According to documentation for InfluxDB's HTTP Write Syntax [2]:

All timestamps are assumed to be Unix nanoseconds unless otherwise specified

Since Information provided by the RTC is hardware specific, I assume the precision cannot be changed. (doubtful)

Solution

I used the precision parameter in the HTTP write syntax in my Arduino Sketch as follows:

HTTPClient http;
       
       http.begin("http://" + _host + ":" + _port + "/write?db=" + _db + "&precision=s");
       http.addHeader("Content-Type", "text/plain");

       int httpResponseCode = http.POST(mes_dat);

The precision value is s (in seconds). This will save the information in InfluxDB in the correct way viz.

name: imu
time                eul_x  eul_y eul_z liac_x liac_y liac_z location nodeid status
----                -----  ----- ----- ------ ------ ------ -------- ------ ------
1537470381000000000 359.31 0     9.81  -0.05  -1.47  9.82   front    node1  0
1537470382000000000 359.37 0     10.81 -0.05  -1.72  9.75   front    node1  0
1537470383000000000 359.37 -0.06 10.81 -0.06  -1.75  9.71   front    node1  0
1537470384000000000 359.37 -0.06 10.81 -0.03  -1.75  9.67   front    node1  0
1537470385000000000 359.37 -0.06 10.81 -0.05  -1.76  9.73   front    node1  0
1537470386000000000 359.37 -0.06 10.75 -0.05  -1.76  9.72   front    node1  0
1537470387000000000 359.37 -0.06 10.75 -0.06  -1.77  9.64   front    node1  0
1537470388000000000 359.37 -0.06 10.75 -0.02  -1.76  9.61   front    node1  0
1537470389000000000 359.37 -0.06 10.75 -0.04  -1.76  9.61   front    node1  0
1537470390000000000 359.37 -0.06 10.75 -0.03  -1.82  9.61   front    node1  0
1537470391000000000 359.37 -0.06 10.63 -0.03  -1.78  9.72   front    node1  0
1537470393000000000 359.37 -0.06 10.63 -0.05  -1.78  9.63   front    node1  0
1537470394000000000 359.37 -0.06 10.63 -0.05  -1.76  9.76   front    node1  0

And Visualization is perfect in Chronograf with all the above mentioned Queries in the question.

[1] Adafruit's DS3231

[2] InfluxDB HTTP Write Documentation