-->
Page 1 of 2

Differentiate Between Deep Sleep Wake-up and Hardware Reset

PostPosted: Tue Nov 29, 2016 2:36 pm
by garyeb
I need to differentiate between an automatic wake-up from deep sleep and restarting after a reset button is pushed on a WeMos D1 Mini (user event). The design is for a very simple, battery-powered button device. The following code always reports a reason code '5' whether waking from deep sleep or receiving a hardware reset signal. If the deep sleep function call is removed, '6' is always returned on a hardware reset. It appears the reset value is set once deep sleep is entered and a hardware reset does not change it. Any ideas? A hardware solution is fine as long as I can detect a user event (pressing a momentary switch).

Thanks.

Code: Select all#include <Arduino.h>
extern "C"
{
  #include "user_interface.h"
}
void setup()
{
  rst_info *rsti;
  rsti = ESP.getResetInfoPtr();
  Serial.begin(115200);
  Serial.println();
  Serial.println("Starting...");
  Serial.println(String("ResetInfo.reason = ") + rsti->reason);
  Serial.println("Sleeping...");
  ESP.deepSleep(5000000, WAKE_RF_DISABLED);
}
void loop() {}

Re: Differentiate Between Deep Sleep Wake-up and Hardware Re

PostPosted: Wed Nov 30, 2016 1:43 am
by ESP_NEWBIE
Before entering deep sleep, you can store a flag in RTC memory (512 Bytes ?) which is not initialized after a reset.

Re: Differentiate Between Deep Sleep Wake-up and Hardware Re

PostPosted: Sun Oct 15, 2017 5:03 pm
by mrtc
Did you ever get any further resolving this issue?

Re: Differentiate Between Deep Sleep Wake-up and Hardware Re

PostPosted: Mon Oct 16, 2017 2:17 am
by schufti
Unfortunately waking from deep sleep is via rst, so hard to differentiate.
Use the EN pin for user reset, this should give a different code.