test wake-up reason
Posted: Tue Aug 20, 2019 4:40 am
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:
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.
I searched on the net, but i didn't find response to this question.
Any idea?
Thanks in advance!
Mauro
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 all
extern "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