esp.deepsleep() overflow

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

esp.deepsleep() overflow

Post by devnull » Sat Feb 25, 2017 1:12 pm

I am using the esp.deepsleep() function, works fine until I try and sleep for 1 hour or more.

This results in numeric overflow, what is the maximum sleep time that can be set using this method ??

Code: Select all

sleepsec = 3600 ## 1 HR
sleepus = sleepsec * 1000000 
esp.deepsleep(sleepus)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: esp.deepsleep() overflow

Post by pythoncoder » Sun Feb 26, 2017 8:25 am

To differentiate short integers from arbitrary precision integers MicroPython uses the MSB. This means that short integers must have b30 == b31. So I think the maximum is 1073s (0x3fffffff // 1000000).
Peter Hinch
Index to my micropython libraries.

jamesb
Posts: 13
Joined: Tue Nov 29, 2016 3:31 am

Re: esp.deepsleep() overflow

Post by jamesb » Sun Feb 26, 2017 10:57 pm

This seems to work:

Code: Select all

    
    rtc = RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

    # check if the device woke from a deep sleep
    if machine.reset_cause() == machine.DEEPSLEEP_RESET:
        print('woke from a deep sleep')

    # set RTC.ALARM0 to fire after 60 mins (waking the device)
    rtc.alarm(rtc.ALARM0, 1000*60*60)

    # put the device to sleep
    machine.deepsleep()
 

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: esp.deepsleep() overflow

Post by devnull » Mon Feb 27, 2017 9:35 am

@jamesb - thanks so much, yes I am aware of that method as well, but I was wondering what the limitation with the more concise esp.deepsleep() was.

Post Reply