fixxx with epoch time we pray to it work

This commit is contained in:
Aurélien Gauthier 2022-06-13 17:51:51 +02:00
parent 367baf5f9a
commit c463b39c56
2 changed files with 6 additions and 33 deletions

View file

@ -15,7 +15,7 @@
#include <Pangodream_18650_CL.h>
#include <secret.h>
#define TOPIC "test-alex"
#define TOPIC "prod"
#define MQTT_ADDRESS "185.233.103.24"
#define MQTT_PORT 1883
#define ESPNAME "esp32-bastien"

View file

@ -35,8 +35,8 @@ WiFiUDP NtpUDP;
*
* @param 7200: jet lag europe time from France (2 * 3600 sec)
*/
NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org" , 7200 , 60000);
//NTPClient TimeClient(NtpUDP, "pool.ntp.org");
//NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org" , 7200 , 60000); // ancienne configuration
NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org");
//-------------------- CONDITION --------------------//
@ -369,6 +369,7 @@ void setup()
TimeClient.begin();
TimeClient.update();
//int rawtime = (TimeClient.getEpochTime()) % 86400; // 86400 = 60sec*60minutes*24heures
unsigned long rawtime = getTime();
@ -424,7 +425,7 @@ void loop()
writeMessage(msg, temp, hum, SENSORS_NUMBER);
TimeClient.update();
TimeClient.getFormattedTime().toCharArray(time, 30);
//TimeClient.getFormattedTime().toCharArray(time, 30);
//tie(year, month, day) = getDate();
@ -439,36 +440,8 @@ void loop()
now = getTime();
//TimeClient.update();
//Serial.println(TimeClient.getFormattedTime());
//Solution to the issue generated by the Ntpclient for the horodatage midnight at two o'clock
// if (time[0] == '0' && (time[1] == '0' || time[1] == '1')){
// if (day == 31){
// if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
// day = 1;
// month++;
// if(month == 13){
// month == 1;
// year++;
// }
// }
// }else if (day == 30){
// if(month == 4 || month == 6 || month == 9 || month == 11){
// day = 1;
// month++;
// }
// }else if(day == 29){
// if(month == 2){
// day = 1;
// month++;
// }
// }else{
// day++;
// }
// }
lenght = sprintf(date,"%s|", ultoa(now, date, 10) /* "|%d-%d-%d ", year, month, day */);
lenght = sprintf(date,"%s", ultoa(now, date, 10) /* "|%d-%d-%d ", year, month, day */);
sprintf(date + lenght, time);
sprintf(date + strlen(date), msg);
MqttClient.publish(TOPIC, date);