Library to deep sleep for days for esp8366

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
costas
Posts: 5
Joined: Tue Jun 20, 2017 5:32 pm

Library to deep sleep for days for esp8366

Post by costas » Tue Jun 20, 2017 5:39 pm

To anyone that might be interested, i have written a library (tested with a wemos d1 mini) to be able to put the board to sleep for a number of hours effectively being able to run stuff once a day (or even more of course). Feedback is welcome. The project can be found here https://github.com/costastf/micropython ... ibrary.git

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

Re: Library to deep sleep for days for esp8366

Post by pythoncoder » Wed Jun 21, 2017 5:23 am

Very nice. Where did you find the information about rtc.memory?
Peter Hinch
Index to my micropython libraries.

costas
Posts: 5
Joined: Tue Jun 20, 2017 5:32 pm

Re: Library to deep sleep for days for esp8366

Post by costas » Wed Jun 21, 2017 6:45 am

Hi @pythoncoder,

from all over the place. First it was this https://github.com/micropython/micropython/issues/2342 that led me on the 71 minute barrier. Then I found an article on arduino for the deep sleep duration (can't find it now) where someone mentioned the rtc memory as a way to keep state. Then I found this https://github.com/micropython/micropython/issues/2138 that basically documents the usage even if it is not officially documented. And that is more or less it...

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Library to deep sleep for days for esp8366

Post by kfricke » Wed Jun 21, 2017 8:16 am

(sadly) Your code is published under the GPL. All core parts of MicroPython and most modules are MIT licensed, this is a drawback for some people.

costas
Posts: 5
Joined: Tue Jun 20, 2017 5:32 pm

Re: Library to deep sleep for days for esp8366

Post by costas » Wed Jun 21, 2017 8:37 am

If you think that this module could be a part of the micropython-lib I wouldn't mind changing the licence to MIT.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Library to deep sleep for days for esp8266

Post by kfricke » Wed Jun 21, 2017 1:38 pm

I do not think that it can be added there, micropython-lib ist the place to look for MicroPython implementations of existing CPython modules. Integrating your module would force other projects to use the GPL license even if they had wisely chosen a more liberal license (like the given example MIT license).

But i did only noticed the license and felt to comment on it, and do not want to start a license discussion.

To get back to topic... how about some notes on the still moderate power consumption of the ESP8266 when in deep sleep? Not that users assume this module to implement ultra low-power modes, which the ESP8266 lacks by nature.

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

Re: Library to deep sleep for days for esp8266

Post by pythoncoder » Thu Jun 22, 2017 6:55 am

kfricke wrote:... how about some notes on the still moderate power consumption of the ESP8266 when in deep sleep? Not that users assume this module to implement ultra low-power modes, which the ESP8266 lacks by nature...
This Espressif link claims 10μA http://bbs.espressif.com/viewtopic.php? ... HT_SLEEP_T. Is this not achievable?

@costas Thanks for the information. I was aware of the 72 minute limitation but I'd missed the memory() method. The link above suggests there are 512 bytes. A little experimentation with the code below produces interesting results. If p >= 493 it produces a 'buffer too long' message. p == 492 produces numerous errors. p <= 490 works. So we have 490 bytes of usable memory available to MicroPython plus an apparent MicroPython bug.

Code: Select all

import machine
rtc = machine.RTC()
p = 490
a = bytes((n & 0xff for n in range(p)))
rtc.memory(a)
for k in range(p):
    if a[k] != rtc.memory()[k]:
        print(a[k], rtc.memory()[k])
Peter Hinch
Index to my micropython libraries.

costas
Posts: 5
Joined: Tue Jun 20, 2017 5:32 pm

Re: Library to deep sleep for days for esp8366

Post by costas » Thu Jun 22, 2017 7:33 am

That is a very cool and interesting find!

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

Re: Library to deep sleep for days for esp8366

Post by pythoncoder » Thu Jun 22, 2017 8:16 am

Indeed. I tested all sizes from 10 to 491 bytes so it seems solid aside from the 492 case. I raised an issue https://github.com/micropython/micropython/issues/3162.

I wonder why memory() returns a bytes object rather than a bytearray? The latter would enable random write access. As written you need to maintain a local bytearray and copy the whole thing to backup RAM. Rather wasteful of scarce RAM. But I suppose it's a detail.
Peter Hinch
Index to my micropython libraries.

costas
Posts: 5
Joined: Tue Jun 20, 2017 5:32 pm

Re: Library to deep sleep for days for esp8366

Post by costas » Thu Jun 22, 2017 8:26 am

I would guess its because this is not a documented feature and as such it has not found any usage to require refinement of the interface. Being so esoteric and with such a very specific usage case it does not come as a surprise that it is not optimised. Of course this is just a guess :)

Post Reply