#include <WiFi.h>
#include "time.h"
const char* ssid = "Wokwi-GUEST"; // Nom de la box Wi-Fi
const char* password = ""; // MDP de la box Wi-Fi
const char* ntpServer = "fr.pool.ntp.org";
const long gmtOffset_sec = 3600 * 1;
const int daylightOffset_sec = 3600 * 0;
long DelaiBoucle = 1800000; // 1800000 30 minutes
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
Serial.println("\nConnecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println("\nConnected to the WiFi network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
// On configure le seveur NTP
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void loop() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
}
if ( timeinfo.tm_hour >= 6 && timeinfo.tm_hour < 13) // Entre 6h et 13h le délai de la boucle est réduit à 30s
{
DelaiBoucle = 30000;
if (timeinfo.tm_min >= 0 && timeinfo.tm_min < 1)
{
Serial.println(&timeinfo, "%c");
}
if (timeinfo.tm_min >= 30 && timeinfo.tm_min < 31)
{
Serial.println(&timeinfo, "%x %X");
}
}
else
{
DelaiBoucle = 1800000;
}
delay(DelaiBoucle);
}