1

I am sending data to an InfluxDB database using the Python client library. The example given uses the time method from the Point class, which is supposed to allow for writing data with a provided timestamp rather than the data received time at the server.

I am using the following imports:

from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
from influxdb_client.domain.write_precision import WritePrecision

And I have the following code segments for constructing the Point and sending it using the write method:

def get_shark_intervals(sharks, buffer):
  for shark in sharks:
    demand    = Shark.decode_readings(shark.read([Shark.DEMAND]))
    interval  = Shark.decode_datetime(shark.read([Shark.INTERVAL]))
    if demand is None or interval is None:
      return
    print(interval)
    buffer.append(
      [
        int(datetime(
          2000 + interval[0],
          interval[1],
          interval[2],
          interval[3],
          interval[4],
          interval[5]
        ).timestamp()),
        "L1",
        shark.get_equipment(),
        shark.get_description(),
        shark.get_nom_voltage(),
        "DEMAND",
        int(demand[0][1])
      ]
    )
    print(buffer[-1][0])
  return
def flush_buffer(influx, buffer):
  len_buffer = len(buffer)
  points = [0] * len_buffer

  for i in range(0, len_buffer):
    point = Point("consumption")                                  \
      .tag("location",        buffer[i][1])                       \
      .tag("equipment",       buffer[i][2])                       \
      .tag("description",     buffer[i][3])                       \
      .tag("nominal_voltage", buffer[i][4])                       \
      .tag("type",            buffer[i][5])                       \
      .field("W",             buffer[i][6])                       \
      .time(buffer[i][0],     write_precision = WritePrecision.S)

    points[i] = point

  influx.write(
    bucket          = BUCKET,
    record          = points,
    write_precision = WritePrecision.S
  )

  buffer = []
  
  return

For the two print statements in my code, I get this output:

Output from print statements with datetime information

The list is formatted as [Year, Month, Day, Hour, Minute, Second], and the Unix timestamp lines up with the items in the list when converted; however, as seen below, InfluxDB appears to be using the server received timestamp when displaying a query:

Example graph of incorrect timestamp

Example graph of incorrect timestamp

This is also seen in the raw data where _time doesn't match the provided timestamps:

Raw data with incorrect time column

Hari
  • 157
  • 2
  • 12
  • When testing additional telemetry with a 1-second sampling interval and a 10-second upload interval, all the timestamps are synchronized to the 10-second intervals, so it appears InfluxDB is ignoring the timestamp in the Point being sent. – Hari Oct 09 '21 at 07:58

0 Answers0