Jelajahi Sumber

Correct influx utc (#1964)

* Update interface_influxdb.cpp

* Correct to UTC
jomjol 3 tahun lalu
induk
melakukan
69583db99e
1 mengubah file dengan 6 tambahan dan 1 penghapusan
  1. 6 1
      code/components/jomjol_influxdb/interface_influxdb.cpp

+ 6 - 1
code/components/jomjol_influxdb/interface_influxdb.cpp

@@ -69,15 +69,20 @@ void InfluxDBPublish(std::string _key, std::string _content, std::string _timest
     strptime(_timestamp.c_str(), PREVALUE_TIME_FORMAT_OUTPUT, &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);  // t is now your desired time_t
 
 
+    struct tm * ptm;
+    ptm = gmtime ( &t );
+    time_t utc = mktime(ptm);
 
 
 //    time_t now;
 //    time_t now;
 //    time(&now);
 //    time(&now);
     char nowTimestamp[21];
     char nowTimestamp[21];
     // pad with zeroes to get nanoseconds
     // pad with zeroes to get nanoseconds
 //    sprintf(nowTimestamp,"%ld000000000", (long) now);
 //    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)");
 //    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;
     std::string payload = _influxDBMeasurement + " " + _key + "=" + _content + " " + nowTimestamp;