【问题标题】:Data written with correct timestamp does not get visualized in Chronograf InfluxDB使用正确时间戳写入的数据不会在 Chronograf InfluxDB 中可视化
【发布时间】:2018-09-20 16:37:01
【问题描述】:

我有一个嵌入式板,它从 IMU 传感器发送信息以及从 RTC 模块接收到的时间戳。

时间戳来自Adafruit's RTClib

代码有一个名为unixtime() 的函数,它为我提供如下时间戳:

1537466106 
1537466107
1537466109

如果我在Online Epoch Converter 中输入上述时间戳,它会为我提供截至今天的正确时间。

我通过 HTTP 发送此信息,信息存储在 InfluxDB 中的imu 测量下,如下所示:

查询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

现在我在机器上运行一个 Chronograf Instance 来可视化上述测量中获得的数据

计时查询

奇怪的是,表格总是显示时间戳指向 1970 年

从数据库中查询单个字段会提供以下输出:

研究

我阅读了 InfluxDB 的文档,它们的时间戳为 nanoseconds 精度。

相反,我上面提到的时间戳其实是正确的,但为什么Chronograf/ InfluxDB不能正确掌握呢?

案例

我从RTClib 获得时间戳为uint32_t,但我不确定如何将其转换为纳秒精度。

我将时间戳信息作为字符串发送,将零连接到字符串是否明智? If So 可能需要多少个零?

【问题讨论】:

    标签: arduino influxdb epoch chronograf


    【解决方案1】:

    硬件

    我正在使用 DS3231 RTC 模块,它提供精度 [1].

    根据 InfluxDB 的 HTTP 写入语法的文档[2]

    除非另有说明,否则所有时间戳均假定为 Unix 纳秒

    由于 RTC 提供的信息是特定于硬件的,因此我假设无法更改精度。 (怀疑)

    解决方案

    我在 Arduino Sketch 的 HTTP 写入语法中使用了precision 参数,如下所示:

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

    precision 的值为 s(以秒为单位)。这将以正确的方式将信息保存在 InfluxDB 中。

    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
    

    并且可视化在 Chronograf 中非常完美,问题中包含上述所有查询。

    [1] Adafruit's DS3231

    [2] InfluxDB HTTP Write Documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-03
      • 2019-01-22
      • 2017-12-15
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      相关资源
      最近更新 更多