Skip to content

Commit

Permalink
Update interface_influxdb.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jomjol committed Feb 8, 2023
1 parent 30a5072 commit a9c5beb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions code/components/jomjol_influxdb/interface_influxdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,21 @@ void InfluxDBPublish(std::string _key, std::string _content, std::string _timest
// Format: #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S%z"
struct tm tm;
strptime(_timestamp.c_str(), PREVALUE_TIME_FORMAT_OUTPUT, &tm);
time_t t = mktime(&tm); // t is now your desired time_t

time_t t = mktime(&tm); // Time in Localtime (looks like timezone is not used by strptime)

struct tm * ptm;
ptm = gmtime ( &t );

time_t utc = mktime(ptm);
utc = 2*t - utc;

// time_t now;
// time(&now);
char nowTimestamp[21];
// pad with zeroes to get nanoseconds
// sprintf(nowTimestamp,"%ld000000000", (long) now);
// 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)");

// LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Test Time Conversion - t: " + std::to_string(t) + ", utc: " + std::to_string(utc) + ", now: " + std::to_string(now) + ", utc_local: " + std::to_string(utc_local));

std::string payload = _influxDBMeasurement + " " + _key + "=" + _content + " " + nowTimestamp;
payload.shrink_to_fit();
Expand Down

0 comments on commit a9c5beb

Please sign in to comment.