Montres ton code pour que l'on puisse voir comment tu as configuré la durée du sommeil, il me semble que le sommeil profond de l'ESP32 peut êtr plus long qu'une heure.
autre solution, 'soft', un peu bâtarde, inspirée de ce qui se fait avec les AVR :
réveil toutes les heures, incrémentation d'un compteur sauvegardé en RTCRAM, rendormissement immédiat si la 24e heure n'est pas atteinte
Remarque : il me semble avoir lu des choses contradictoires (32bits vs 64 bits) concernant le nombre maximal de µS du sommeil profond mais je n'ai jamais tenté de dépasser l'heure n'ayant pas encore rencontré le besoin
Essaites tout simplement avec la fonction signalée par lesept qui ne renvoie pas de valeur (la fonction que l'ai indiqué n'est peut être pas accessible par l'IDE Arduino)
pour mettre en sommeil avec réveil a bout du temps fixé içi par exemple par TIME_TO_SLEEP en secondes
Juste pour tester la possibilité de réveil au bout d'environ 24h
De mon côté je viens de lancer l'exemple TimerWakeUP du groupe d'exemples ESP32/DeepSleep avec la valeur 7200 pour TIME_TO_SLEEP...... RdV dans 2h !
Réveil au bout de 2h constaté içi :
J'ai l'impression que la première prend un uint64_t en paramètre quand la seconde , dépréciée, prend un uint32_t.
D'ou l'intérêt de partir des exemples actuels (à défaut de doc de référence actualisée) et non des tutoriels .....qui copient des tutoriels ... basés sur des données obsolètes.
(il manque une notion de date de péremption pour nombre de tutoriels ou du moins l'indication des versions d'IDE et de 'core' utilisés !!)
Réveil de l'ESP32 au bout de 10h : test concluant (durée exacte sur mon module : 9h53)
Nouveau test lançé sur 24h
à demain matin !
Pour info le code est celui de l'exemple TimerWakeUP + un envoi de donnée vers ThinkSpeak à chaque réveil
IDE Arduino 1.8.10 et un Core ESP32/Arduino v 1.0.4
Grand Merci.
Je peux développer mon code un peu plus. Je fais des tests avec ce code pas bête:
Ajuste le temps de sommeil pour les problèmes de wifi et pour les périodes de jour ou de nuit.
Heureusement que le jardin ne se réveille qu'au printemps. :O)
/*
https://forum.arduino.cc/index.php?topic=626840.0
I want to set a deep sleep period for the board more that 1h.
I have wrote the code and it compiles fine. My problem is that
when I execute and use sleep period greater than the value of
long signed int (in micro seconds) it doen't work..
The reason of micro seconds is that the definition of the
wake up timer must be done in micro seconds.
When I set a timer less than long signed int
( <2.147.483.647 micro seconds) it works fine.
Also I tried to use the uint64_t data type but
it doesn't work either.
*/
#include <WiFi.h>
#include <NTPClient.h> //For NTP Server
#include <WiFiUdp.h> //For NTP Server
#include "esp_deep_sleep.h"
#define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds for deep sleep usage
RTC_DATA_ATTR int TIME_TO_SLEEP_WiFi = 10; // Time to sleep in case of unavailable WiFi (This is the first sleep)
#define TIME_TO_SLEEP_MAX 80ULL // MAX Time to sleep in case of repeatable unsuccessfull connection attempts
#define TIME_TO_SLEEP_CASE1 3600ULL // Time to sleep (3600s = 1h) in if the time is 06:00 - 20:00
#define TIME_TO_SLEEP_CASE2 18000ULL //2.5h Time to sleep (9000s = 2.5h) if time isn't 06:00 - 20:00
#define DAY_PERIOD_START 60000 // 06:00 in the morning
#define DAY_PERIOD_END 200000 // 20:00 in the morning
RTC_DATA_ATTR int bootCount = 0;
const char* ssid = "23JANVIER-2012_Network_1";
const char* password = "cvq1-3bhy-afp6";
//http://189.143.0.107/
//24:6F:28:17:F9:50
long timezone = -5;
uint8_t daysavetime = 1;
struct tm tmstruct;
unsigned long currentMillis;
const unsigned long period = 10000; //set the period that esp32 will try to connect with WIFI in ms
// Variables to save date and time
String formattedDate;
String timeStamp;
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch (wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
}
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
++bootCount;
/*------------------------------------------------------------------------------------------------------*/
while (WiFi.status() != WL_CONNECTED) {
currentMillis = millis(); //Assign the ms have been passed since ESP32 code start running
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
if (currentMillis > period) {
WiFi.disconnect();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP_WiFi * uS_TO_S_FACTOR);
Serial.println("Going to sleep now for " + String(TIME_TO_SLEEP_WiFi) + " Seconds" + " Due to WiFi unavailability");
esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
Serial.println("Configured all RTC Peripherals to be powered down in sleep");
Serial.println("Sleep for ..................." + String(TIME_TO_SLEEP_WiFi));
while (TIME_TO_SLEEP_WiFi < TIME_TO_SLEEP_MAX) { // While the sleep time is less than the predefined limit keep double the sleep time. When the sleep time exceeds the limit then keep a constant sleep time equal to the limit.
TIME_TO_SLEEP_WiFi = TIME_TO_SLEEP_WiFi * 2; // Double the sleep time
esp_deep_sleep_start();
}
TIME_TO_SLEEP_WiFi = TIME_TO_SLEEP_MAX; // Set the sleep time equal to the limit
esp_deep_sleep_start();
}
Serial.println("Connecting to WiFi..");
delay(1000);
}
/*-----------------------------------------------------------------------------------------------------*/
Serial.print("Connected to ");
Serial.print(ssid);
Serial.println(" network");
Serial.println(WiFi.macAddress());
Serial.println(WiFi.RSSI());
TIME_TO_SLEEP_WiFi = 10;
/*-----------------------------------------------------------------------------------------------------*/
timeClient.begin(); // Initialize a NTPClient to get time
// Set offset time in seconds to adjust for your timezone, for example:
timeClient.setTimeOffset(-18000); //Cyprus Time Zone GMT -5 = -18000
/*-----------------------------------------------------------------------------------------------------*/
esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
Serial.println("Configured all RTC Peripherals to be powered down in sleep");
Serial.println("NTP Client initialized");
delay(100);
}
void loop() {
while (!timeClient.update()) {
timeClient.forceUpdate();
}
// The formattedDate comes with the following format:
// 2018-05-28T16:00:13Z
formattedDate = timeClient.getFormattedDate();
Serial.print("Date: ");
Serial.println(formattedDate);
Serial.print("The time is: ");
String timeE = formattedDate.substring(formattedDate.indexOf("T") + 1, formattedDate.length() - 1);
Serial.println(timeE);
// Extract tha time part into clear integer
int splitT = formattedDate.indexOf("T"); // The output is the number 10 , splitT=10 (Start counting from 0)
String timeStamp1 = formattedDate.substring(splitT + 1, splitT + 3 ); // splitT+1 = 11, formattedDate.length()-1 = 19 --> 16:00:13Z
String timeStamp2 = formattedDate.substring(splitT + 4, splitT + 6 );
String timeStamp3 = formattedDate.substring(splitT + 7, splitT + 9 );
timeStamp = timeStamp1 + timeStamp2 + timeStamp3;
int result = timeStamp.toInt();
Serial.println("_138-int result = timeStamp.toInt(); ");
Serial.println(result);
// Check the time in order to adjust the time to sleep period
if (result >= DAY_PERIOD_START && result <= DAY_PERIOD_END) {
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP_CASE1 * uS_TO_S_FACTOR);
esp_deep_sleep_start();
} else {
Serial.println("Going to sleep for 2.5h");
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP_CASE2 * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
}
Normalement, quand on met l'ESP32 en deep sleep, il se réveille et relance le setup (il y a peut-être des options pour reprendre l'exécution au point où il l'a laissée, mais je ne sais pas si ça existe pour le deep sleep). Du coup, toutes les instructions sont mises dans le setup, et la loop reste vide puisqu'on vise une consommation minimale.
Donc, tu peux déplacer le contenu de la loop à la fin du setup. Ca ne changera pas grand chose, mais ça sera plus propre...
Le reveil du deep-sleep est exclusivement un redémarrage, un 'redémarrage à chaud' : une petite RAM reste alimentée pendant le sommeil et on retrouve son contenu au réveil.
Dans mes applications de ce type le préfère laisser loop() vide pour mettre en évidence le fonctionnement.
lesept:
Normalement, quand on met l'ESP32 en deep sleep, il se réveille et relance le setup (il y a peut-être des options pour reprendre l'exécution au point où il l'a laissée, mais je ne sais pas si ça existe pour le deep sleep). Du coup, toutes les instructions sont mises dans le setup, et la loop reste vide puisqu'on vise une consommation minimale.
Donc, tu peux déplacer le contenu de la loop à la fin du setup. Ca ne changera pas grand chose, mais ça sera plus propre...
Le placer dans un while ou simplement le copier-coller (avec les ajustements qui s'imposent)?