Library to deep sleep for days for esp8366
Library to deep sleep for days for esp8366
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Library to deep sleep for days for esp8366
Very nice. Where did you find the information about rtc.memory?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Library to deep sleep for days for esp8366
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...
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...
Re: Library to deep sleep for days for esp8366
(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.
Re: Library to deep sleep for days for esp8366
If you think that this module could be a part of the micropython-lib I wouldn't mind changing the licence to MIT.
Re: Library to deep sleep for days for esp8266
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.
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Library to deep sleep for days for esp8266
This Espressif link claims 10μA http://bbs.espressif.com/viewtopic.php? ... HT_SLEEP_T. Is this not achievable?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...
@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.
Index to my micropython libraries.
Re: Library to deep sleep for days for esp8366
That is a very cool and interesting find!
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Library to deep sleep for days for esp8366
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.
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.
Index to my micropython libraries.
Re: Library to deep sleep for days for esp8366
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