← index #6997Issue #3961
Related · medium · value 0.752
QUERY · ISSUE

Esp8266 doesn't execute code after woke up from deep sleep

openby lazarvgdopened 2021-03-05updated 2026-03-24
port-esp8266proposed-close

I have a problem with waking ESP8266 from deep sleep. Here is my code that i run:

import network
import machine
import time
from machine import RTC
import ntptime
from wdt import WDT

def deep_sleep(msecs):
  #configure RTC.ALARM0 to be able to wake the device
  rtc = machine.RTC()
  rtc.irq(trigger=rtc.ALARM0, wake=machine.)
  # set RTC.ALARM0 to fire after Xmilliseconds, waking the device
  rtc.alarm(rtc.ALARM0, msecs)
  #put the device to sleep
  machine.deepsleep()

wdt=WDT()
led = machine.Pin(2, machine.Pin.OUT)

sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if.scan()                             # Scan for available access points
sta_if.connect("TS-C99W", "VyHPS8ZJ") # Connect to an AP
sta_if.isconnected()    
print(sta_if.isconnected())
rtc = RTC()

while True:
    if machine.reset_cause() == machine.DEEPSLEEP_RESET:
        print('woke from a deep sleep')
    else:
        print('power on or hard reset')
    for i in range(10):
        led.off()
        time.sleep(1)
        led.on()
        time.sleep(1)
    print(sta_if.isconnected())
    ntptime.settime() # set the rtc datetime from the remote server
    print(rtc.datetime())    # get the date and time in UTC
    time.sleep(0.25)
    deep_sleep(20000)
    wdt.feed()

The output that I am getting is this:

image

The board that I am using is this:

image

I am not sure why is this happening? What am I doing wrong?
Please help me to solve this issue.

Thanks

CANDIDATE · ISSUE

ESP8266 crashes on wake from deepsleep

closedby peterhinchopened 2018-07-19updated 2024-08-28
port-esp8266

This was reported on the forum.

If the following code is pasted at the REPL the board wakes after 10s but crashes: there is no response to the REPL or to pings, and the red LED on the reference board is lit.

import machine
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
rtc.alarm(machine.RTC.ALARM0, 10000)
machine.deepsleep()
machine.reset()  # Crashes with or without this

A second issue is that the handler kwarg to rtc.irq is rejected:

rtc.irq(trigger=rtc.ALARM0, handler=lambda *_ : None, wake=machine.DEEPSLEEP)

produces TypeError: extra keyword arguments given.

Hardware: Adafruit Feather Huzzah, build:

MicroPython v1.9.4-227-gab02abe-dirty on 2018-07-19; ESP module with ESP8266

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied