Skip to content

Commit

Permalink
Added SLEEP_DEEP_NOWIFI because hibernating hits a hardware CPU bug, …
Browse files Browse the repository at this point in the history
…see espressif/esp-idf#494 for details.
  • Loading branch information
jackjansen committed Dec 12, 2019
1 parent 180580b commit 02f3f53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = nodemcuv2-example-bleled
default_envs = esp32thing-example-bleled

[env]
framework = arduino
Expand Down
19 changes: 14 additions & 5 deletions src/iotsaBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ void IotsaBatteryMod::setup() {
#ifdef ESP32
useExtraWakeDuration = (esp_sleep_get_wakeup_cause() == 0);
// If we are awaking from sleep we may want top disable WiFi
if (sleepMode == SLEEP_HIBERNATE_NOWIFI && !useExtraWakeDuration) {
//
// NOTE: there is a bug in the revision 1 ESP32 hardware, which causes issues with wakeup from hibernate
// to _not_ record this as a wakeup but in stead as an external reset (even though the info printed at
// boot time is correct). For this reason it may be better to use deep sleep in stead of hibernate.
// Various workarounds I've tried did not work.
// See https://github.com/espressif/esp-idf/issues/494 for a description.
//
if ((sleepMode == SLEEP_HIBERNATE_NOWIFI || sleepMode == SLEEP_DEEP_NOWIFI) && !useExtraWakeDuration) {
IFDEBUG IotsaSerial.println("Disabling wifi");
if (iotsaConfig.wifiEnabled) {
IFDEBUG IotsaSerial.println("Wifi already enabled?");
}
iotsaConfig.disableWifiOnBoot = true;
}
#endif
Expand Down Expand Up @@ -221,14 +232,12 @@ void IotsaBatteryMod::loop() {
}
if (iotsaConfig.wifiEnabled) esp_wifi_stop();
esp_bt_controller_disable();
if (sleepMode == SLEEP_DEEP) {
esp_deep_sleep_start();
} else {
if (sleepMode == SLEEP_HIBERNATE || sleepMode == SLEEP_HIBERNATE_NOWIFI) {
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
esp_deep_sleep_start();
}
esp_deep_sleep_start();
IFDEBUG IotsaSerial.println("esp_*_sleep_start() failed?");
#else
ESP.deepSleep(sleepDuration*1000LL);
Expand Down
1 change: 1 addition & 0 deletions src/iotsaBattery.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum IotsaSleepMode : uint8_t {
SLEEP_LIGHT,
SLEEP_DEEP,
SLEEP_HIBERNATE,
SLEEP_DEEP_NOWIFI,
SLEEP_HIBERNATE_NOWIFI
};

Expand Down
3 changes: 3 additions & 0 deletions src/iotsaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ static const char* getBootReason() {
}
#else
RESET_REASON r = rtc_get_reset_reason(0);
RESET_REASON r2 = rtc_get_reset_reason(1);
// Determine best reset reason
if (r == TG0WDT_SYS_RESET || r == RTCWDT_RTC_RESET) r = r2;
static const char *reasons[] = {
"0",
"power",
Expand Down

0 comments on commit 02f3f53

Please sign in to comment.