timestamp fix

This commit is contained in:
Aurélien Gauthier 2022-05-24 16:50:46 +02:00
parent a21f0104d8
commit f0a0ccc395
2 changed files with 8 additions and 8 deletions

View file

@ -23,8 +23,7 @@
#define SENSORS_NUMBER 5 #define SENSORS_NUMBER 5
#define DHT22 22 #define DHT22 22
//comment for the test part this is the good frequency //comment for the test part this is the good frequency
//#define TIME_TO_SLEEP 598 #define TIME_TO_SLEEP 598
#define TIME_TO_SLEEP 8
#define US_TO_S_FACTOR 1000000 #define US_TO_S_FACTOR 1000000
#define R2 100 #define R2 100
#define R3 10 #define R3 10

View file

@ -1,11 +1,11 @@
#include "main.h" #include "main.h"
#include "NTPClient.h" #include "NTPClient.h"
//#include "driver/"
#include <sys/time.h> #include <sys/time.h>
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
//extern "C" void f(int); // one way
using namespace std; using namespace std;
@ -16,7 +16,7 @@ float hum[SENSORS_NUMBER];
WiFiClient WifiClient; WiFiClient WifiClient;
PubSubClient MqttClient(WifiClient); PubSubClient MqttClient(WifiClient);
WiFiUDP NtpUDP; 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); Pangodream_18650_CL Battery(ADC_PIN, CONV_FACTOR, READS);
//-------------------- FONCTIONS --------------------// //-------------------- FONCTIONS --------------------//
@ -98,6 +98,8 @@ std::tuple<int, int, int> getDate()
synctime.tv_sec = rawtime; synctime.tv_sec = rawtime;
synctime.tv_usec = 0; synctime.tv_usec = 0;
if(settimeofday(&synctime,NULL) != 0) std::cout << "error\n" ; if(settimeofday(&synctime,NULL) != 0) std::cout << "error\n" ;
setenv("TZ", "CEST+2", 1);
tzset();
struct tm *ti; struct tm *ti;
ti = localtime(&rawtime); ti = localtime(&rawtime);
@ -116,6 +118,7 @@ unsigned long getTime() {
return(0); return(0);
} }
time(&now); time(&now);
Serial.println(now);
return now; return now;
} }
//-------------------- Création de trames --------------------// //-------------------- Création de trames --------------------//
@ -123,9 +126,7 @@ unsigned long getTime() {
void writeMessage(char *txt, float *temp, float *hum, int number) void writeMessage(char *txt, float *temp, float *hum, int number)
{ {
int chargelvl = Battery.getBatteryChargeLevel(); int chargelvl = Battery.getBatteryChargeLevel();
//float homeValue = 3.3 * analogRead(ADC_PIN) / 2048; for test measurement time_t rawtime = TimeClient.getEpochTime();
//float homeValue1 = 1.7 * analogRead(ADC_PIN) / 1000;
time_t rawtime = TimeClient.getEpochTime();
switch (number) 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]); 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; break;
case 5: 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; break;
case 6: 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]); 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]);