Arduino and Manual timestamps

Hi,

I’m learning how to write to influxDB from a Wemos Mini, This is a new and testing experience for me. I am writing polled data, batched and not batched, to influxDB fine. However, the data I need to collect is from an interrupt which has the knock-on effect that I need to manage timestamps myself.

Does anyone have any Arduino code that I can use to learn from, I learn from examples of code rather than reading manuals. I’ve done some googling and looke don hear but without any sucsess.

I’m just trying to understand how to manually provide a time stamp, I’m already doing this;

sensor.addField(“blink”, 1);

and then

client.writePoint(sensor);

Just struggling to work out how to manually set time stamp rather than letting the InfluxDB Client set one for me.

Hope this makes sense and someone will help.

TIA

Hi, what library are you using ? Is this for influxdb v1 or v2 ?

Hi,

Thanks for getting back to me.

I am using the Arduino Library 3.3.0, specifically this one;

GitHub - tobiasschuerg/InfluxDB-Client-for-Arduino: Simple library for sending measurements to an InfluxDB with a single network request. Supports ESP8266 and ESP32..

Specifcally I don’t understand how to apply this part;
If you want to manage timestamp on your own, there are several ways how to set timestamp explicitly.

  • setTime(WritePrecision writePrecision) - Sets timestamp to actual time in desired precision
  • setTime(unsigned long long timestamp) - Sets timestamp in an offset since epoch. Correct precision must be set InfluxDBClient::setWriteOptions.
  • setTime(String timestamp) - Sets timestamp in an offset since epoch. Correct precision must be set InfluxDBClient::setWriteOptions.

The getTime() method allows copying timestamp between points.

thanks,

J

Are you collecting data in real-time? If yes, wouldn’t you want to use the current time as the timestamp?

For precision, I would suggest going with millisecond accuracy.

1 Like

I’m not really no, it’s counting the flashes of my electricity metere - a job I am currently running on a Pi which seems a bit overkill.

Because the flashes are interrupt driven and I am told I cannot put too much in the interrupt i have to process the InfluxDB stuff outside the interrupt so I store them in an array and then write them to Influx. If I have the influxDB write in the interrupt it’ll crash the Wemos :slight_smile:

Hopefully that makes sense.

J

Got it. Is it possible to do something inbetween? At the point the interrupt fires prepare the line protocol record and also grab the timestamp of “now” , and then push it onto the array ?

Edit: if you’re open to it, would you mind you sharing that part of the code in a </> code block ?