From f0a0ccc39593760b11b7ecd1b8c58727aa8a3315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Gauthier?= Date: Tue, 24 May 2022 16:50:46 +0200 Subject: [PATCH] timestamp fix --- include/main.h | 3 +-- src/main.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/main.h b/include/main.h index b17c237..4cd4897 100644 --- a/include/main.h +++ b/include/main.h @@ -23,8 +23,7 @@ #define SENSORS_NUMBER 5 #define DHT22 22 //comment for the test part this is the good frequency -//#define TIME_TO_SLEEP 598 -#define TIME_TO_SLEEP 8 +#define TIME_TO_SLEEP 598 #define US_TO_S_FACTOR 1000000 #define R2 100 #define R3 10 diff --git a/src/main.cpp b/src/main.cpp index cd64668..15a0480 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,11 @@ #include "main.h" #include "NTPClient.h" +//#include "driver/" #include #include #include #include -//extern "C" void f(int); // one way using namespace std; @@ -16,7 +16,7 @@ float hum[SENSORS_NUMBER]; WiFiClient WifiClient; PubSubClient MqttClient(WifiClient); WiFiUDP NtpUDP; -NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org", 0, 60000); +NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org", 7200, 60000); // 7200 = 2 * 3600 sec pour le décalage horaire Pangodream_18650_CL Battery(ADC_PIN, CONV_FACTOR, READS); //-------------------- FONCTIONS --------------------// @@ -98,6 +98,8 @@ std::tuple getDate() synctime.tv_sec = rawtime; synctime.tv_usec = 0; if(settimeofday(&synctime,NULL) != 0) std::cout << "error\n" ; + setenv("TZ", "CEST+2", 1); + tzset(); struct tm *ti; ti = localtime(&rawtime); @@ -116,6 +118,7 @@ unsigned long getTime() { return(0); } time(&now); + Serial.println(now); return now; } //-------------------- Création de trames --------------------// @@ -123,9 +126,7 @@ unsigned long getTime() { void writeMessage(char *txt, float *temp, float *hum, int number) { int chargelvl = Battery.getBatteryChargeLevel(); - //float homeValue = 3.3 * analogRead(ADC_PIN) / 2048; for test measurement - //float homeValue1 = 1.7 * analogRead(ADC_PIN) / 1000; - time_t rawtime = TimeClient.getEpochTime(); + time_t rawtime = TimeClient.getEpochTime(); switch (number) { @@ -142,7 +143,7 @@ void writeMessage(char *txt, float *temp, float *hum, int number) sprintf(txt, "|%s|%0.2f %0.2f %0.2f %0.2f|%0.2f %0.2f %0.2f %0.2f", CLUSTER, temp[0], temp[1], temp[2], temp[3], hum[0], hum[1], hum[2], hum[3]); break; case 5: - sprintf(txt, "|%s|%0.2f %0.2f %0.2f %0.2f %0.2f|%0.2f %0.2f %0.2f %0.2f %0.2f|%d|%lu|%lu", CLUSTER, temp[0], temp[1], temp[2], temp[3], temp[4], hum[0], hum[1], hum[2], hum[3], hum[4], chargelvl, getTime(), rawtime); + sprintf(txt, "|%s|%0.2f %0.2f %0.2f %0.2f %0.2f|%0.2f %0.2f %0.2f %0.2f %0.2f|%d", CLUSTER, temp[0], temp[1], temp[2], temp[3], temp[4], hum[0], hum[1], hum[2], hum[3], hum[4], chargelvl); break; case 6: sprintf(txt, "|%s|%0.2f %0.2f %0.2f %0.2f %0.2f %0.2f|%0.2f %0.2f %0.2f %0.2f %0.2f %0.2f", CLUSTER, temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], hum[0], hum[1], hum[2], hum[3], hum[4], hum[5]);