diff --git a/linky_tic.ino b/linky_tic.ino index 136267e..e01497e 100644 --- a/linky_tic.ino +++ b/linky_tic.ino @@ -16,7 +16,7 @@ ESP8266WebServer server(HTTP_PORT); #endif // Durée de sommeil en microsecondes (par exemple, 5 secondes) -const int sleepDuration = 5 * 1000000; +const int sleepDuration = 1 * 1000000; // Fonction pour configurer et connecter au réseau Wi-Fi void setup_wifi() { @@ -116,8 +116,21 @@ void setup_serial() { // Fonction pour mettre l'ESP8266 en mode deep sleep void goToDeepSleep() { - DebugPort.println("Going to deep sleep..."); - ESP.deepSleep(sleepDuration); + DebugPort.println("Going to deep sleep..."); + ESP.deepSleep(sleepDuration); +} + +void goToLightSleep() { + DebugPort.println("Going to light sleep..."); + wifi_set_opmode(NULL_MODE); // Turn off Wi-Fi + wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // Set light sleep mode + wifi_fpm_open(); + //gpio_pin_wakeup_enable(GPIO_ID_PIN(D1), GPIO_PIN_INTR_LOLEVEL); // Enable wakeup on GPIO + //wifi_fpm_do_wakeup_gpio(true); + //wifi_fpm_set_wakeup_gpio_mode(WAKEUP_GPIO_MODE_KEEP_HIGH); + wifi_fpm_set_wakeup_cb(loop); + wifi_fpm_do_sleep(sleepDuration); // Sleep + delay(20); // Short delay to allow the ESP8266 to enter sleep mode } // Fonction d'initialisation principale @@ -139,11 +152,14 @@ void setup() { // Boucle principale void loop() { + server.handleClient(); readTicPort(); + delay(1000); - // Si aucune requête n'est en cours, mettre l'ESP8266 en mode deep sleep - if (server.client().available() == 0) { - goToDeepSleep(); - } -} + // Si aucune requête n'est en cours, mettre l'ESP8266 en mode deep sleep +/* + if (server.client().available() == 0) { + goToLightSleep(); + }*/ +} \ No newline at end of file