Skip to content
  • Damien George's avatar
    esp8266: Implement basic deep-sleep capabilities. · 32d7cf6e
    Damien George authored
    Use the machine.deepsleep() function to enter the sleep mode.  Use the
    RTC to configure the alarm to wake the device.
    
    Basic use is the following:
    
        import machine
    
        # configure RTC's ALARM0 to wake device from deep sleep
        rtc = machine.RTC()
        rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
    
        # do other things
        # ...
    
        # set ALARM0's alarm to wake after 10 seconds
        rtc.alarm(rtc.ALARM0, 10000)
    
        # enter deep-sleep state (system is reset upon waking)
        machine.deepsleep()
    
    To detect if the system woke from a deep sleep use:
    
        if machine.reset_cause() == machine.DEEPSLEEP_RESET:
            print('woke from deep sleep')
    32d7cf6e