2

In a project powered by batteries, the ESP8266 should go to deep sleep for long time, having RF disabled. After some number of sleep cycles, it shall restart with RF enabled, synchronize time via NTP, and again go to sleep. Think this could work with a counter saved in RTC Memory or SPIFFS.

Additionally, s.o. should be able to wake up via push button (at any time), which should result in different behaviour (running as WiFi AP, allowing for configuration of new WiFi credentials).

The question is: Is it possible to find out what did wake the ESP (timer or pushbutton)?

Edit: Using external circuitry this might be possible. To avoid this, we switch to ESP32, which is an overkill for the project, but easy to find out the source of the wakeup (and with the possibility to use touch sensors). Additionally, ESP32 allows for easy use of "Preferences" in NVR and variables in RTC memory (when using the Arduino IDE), which will survive deep sleep (RTC) and even reset/power loss (NVR).

4
  • 1
    Does this answer your question? Wake up ESP8266 from deepSleep with a button
    – Juraj
    Jan 23 at 6:41
  • Well, not really. Resetting the ESP with a button is not the problem; in both cases /by button/by timer the ESP will be reset, running through setup() code. But how to know why it was reset? I read something about rtc_get_reset_reason() and ESP.getResetReason(); will try that and report on success.
    – ridgy
    Jan 23 at 11:14
  • In case of wakeup from deep sleep, rtc_get_reset_reason() always responds with "wakeup from deep sleep" - that is correct, but does not help here.
    – ridgy
    Jan 24 at 17:00
  • 1
    it is the same reset with button and with io 16. the software can't distinguish it. the reset with io 16 is a workaround for a bug in ROM code of the esp8266
    – Juraj
    Jan 24 at 17:05
0

Place a capacitor on the ESP side of the button to one power rail or the other (my preference is to ground, but either should work), and have the setup() routine reads the state of the pushbutton switch as it's first instruction. You probably don't even need the capacitor, but if you don't have it, you'll have to read the switch state multiple times to account for possible contact bounce.

If the ESP wakes up due to a timer, there will be no activity on the PB line; if it wakes up due to the PB being pressed, there will be activity on the PB line for several 10's of millisec no matter how quickly it is pressed and released.

2
  • The only button I know to wakeup an ESP8266 is the reset button - and this one as well has to be used by the timer. Or am I mistaken?
    – ridgy
    Jan 27 at 17:38
  • Ah, I thought the OP was referring to an external button. This solution still might work if the state of the reset button can be read programmatically during setup().
    – starship15
    Jan 28 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.