Skip to content

Commit

Permalink
Correct influx utc (#1964)
Browse files Browse the repository at this point in the history
* Update interface_influxdb.cpp

* Correct to UTC
  • Loading branch information
jomjol authored Feb 2, 2023
1 parent 2a8df9d commit 69583db
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion code/components/jomjol_influxdb/interface_influxdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ void InfluxDBPublish(std::string _key, std::string _content, std::string _timest
strptime(_timestamp.c_str(), PREVALUE_TIME_FORMAT_OUTPUT, &tm);
time_t t = mktime(&tm); // t is now your desired time_t

struct tm * ptm;
ptm = gmtime ( &t );
time_t utc = mktime(ptm);

// time_t now;
// time(&now);
char nowTimestamp[21];
// pad with zeroes to get nanoseconds
// sprintf(nowTimestamp,"%ld000000000", (long) now);
sprintf(nowTimestamp,"%ld000000000", (long) t);
// sprintf(nowTimestamp,"%ld000000000", (long) t); // Localtime
sprintf(nowTimestamp,"%ld000000000", (long) utc); // UTC


// LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Test Time Conversion - t: " + std::to_string(t) + ", utc: " + std::to_string(utc));
// LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Test Time Conversion - now: " + std::to_string(now) + ", timestamp: " + std::to_string(t) + "(correct time not used yet)");

std::string payload = _influxDBMeasurement + " " + _key + "=" + _content + " " + nowTimestamp;
Expand Down

0 comments on commit 69583db

Please sign in to comment.