So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By mauro.ros
#83520 Hi guys, I'm a new user and since some month I play with ESP8266.

For my application, I need to distinguish the reason wake-up between "DeepSleep" and "RST button pressed".
I need to send to sleep the device eveytime it done the work, and wake-up it every n minutes or if I press the button.
This is the test code:
Code: Select allextern "C" {
#include <user_interface.h>
}

void setup() {
  char buff[32];
 
  Serial.begin(115200);
  Serial.println("\n");
 
  switch (ESP.getResetInfoPtr()->reason) {
   
    case REASON_DEFAULT_RST:
      // do something at normal startup by power on
      strcpy_P(buff, PSTR("Power on"));
      break;
     
    case REASON_WDT_RST:
      // do something at hardware watch dog reset
      strcpy_P(buff, PSTR("Hardware Watchdog"));     
      break;
     
    case REASON_EXCEPTION_RST:
      // do something at exception reset
      strcpy_P(buff, PSTR("Exception"));     
      break;
     
    case REASON_SOFT_WDT_RST:
      // do something at software watch dog reset
      strcpy_P(buff, PSTR("Software Watchdog"));
      break;
     
    case REASON_SOFT_RESTART:
      // do something at software restart ,system_restart
      strcpy_P(buff, PSTR("Software/System restart"));
      break;
     
    case REASON_DEEP_SLEEP_AWAKE:
      // do something at wake up from deep-sleep
      strcpy_P(buff, PSTR("Deep-Sleep Wake"));
      break;
     
    case REASON_EXT_SYS_RST:
      // do something at external system reset (assertion of reset pin)
      strcpy_P(buff, PSTR("External System"));
      break;
     
    default: 
      // do something when reset occured for unknown reason
      strcpy_P(buff, PSTR("Unknown"));     
      break;
  }

  Serial.printf("\n\nReason for reboot: %s\n", buff);
  Serial.println("----------------------------------------------");
}

void loop() {
  ESP.deepSleep(10e6);
}


Unfortunately, as you see in my test report, after the first "RST button pressed", the response is always "DeepSleep", whether it presses the buttone, or if I wait for it to wake up.
Reason for reboot: External System

Reason for reboot: Deep-Sleep Wake

Reason for reboot: Deep-Sleep Wake

Reason for reboot: Deep-Sleep Wake

. . .


I searched on the net, but i didn't find response to this question.
Any idea?

Thanks in advance!
Mauro
User avatar
By Wene
#83561 Hello

I had the same issue. The ESP - in my case a Wemos D1 Mini - isn´t able to differentiate between reset and wake from RTC sleep. In my opinion the reason for this is the same signal at reset and RTC wakeup. Both tear RST to ground.

For this situation this circuit could help.
https://easyeda.com/wene111/wemos_reset_recognition

On pressing the button both transistors open and reset the Wemos and tear D5 to ground. After releasing the button Q2 closes and the Wemos could start up. Q1 is kept open by capacitor C1 for some time. First thing in programm is to set D5 pullup and read it. If it´s LOW startup is from button.

Reset from RTC couldn´t go back trough transitor Q2 therefore D5 is HIGH after startup.

Code: Select allvoid setup() {
 pinMode(BUTTON_PIN,INPUT_PULLUP);
 bool button=digitalRead(BUTTON_PIN);
 if button
     Serial.println("Wakeup from RTC");
else
     Serial.println("Wakeup from Button");

}
User avatar
By mauro.ros
#83567 Hi!

thanks for your answer; I update to the last core version (currently 2.5.2), but it works in the same mode, using the ESP.getResetReason() method too.

Mauro