ESP8266 RTC memory ?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Niallp
Posts: 9
Joined: Sun Nov 29, 2015 10:25 pm

ESP8266 RTC memory ?

Postby Niallp » Wed Mar 15, 2017 9:07 pm

Is there any MicroPython mechanism for using the RTC memory on the ESP8266 ? Or is it already in use internally ? I'd like to retain some values between deep sleeps. (didn't find anything in the documentation).

thx.

gdr
Posts: 1
Joined: Wed Jul 05, 2017 11:46 am

Re: ESP8266 RTC memory ?

Postby gdr » Wed Jul 05, 2017 11:52 am

Same question. rtc.memory() does not save anything.

>>> import machine
>>> rtc = machine.RTC()
>>> rtc.memory(b'hello')
>>> rtc.memory()
b'hello'

restart board

>>> import machine
>>> rtc = machine.RTC()
>>> rtc.memory()
b''

Damien
Site Admin
Posts: 538
Joined: Mon Dec 09, 2013 5:02 pm

Re: ESP8266 RTC memory ?

Postby Damien » Thu Jul 06, 2017 4:07 am

@gdr what do you do when you "restart board"? I've tested your code and it works (the memory is retained) when the esp8266 is hard-reset (using the RST button on the Adafruit Feather Huzzah board). The memory is also retained after waking from deepsleep.

g-sam
Posts: 6
Joined: Sun Jun 04, 2017 10:12 am

Re: ESP8266 RTC memory ?

Postby g-sam » Mon Jul 10, 2017 3:05 pm

I believe I have encountered the same problem as @gdr, but things are a little more complicated: sometimes, rtc.memory does succeed, but not always...Try the following:

==================================
import machine
import esp

INIT_SECONDS = 23

rtc = machine.RTC()

print('woken with task', rtc.memory())

if rtc.memory() == b'init':
rtc.memory(b'read')
print('going to sleep, will wake to ', rtc.memory())
esp.deepsleep(INIT_SECONDS * 1000000)

rtc.memory(b'init')
=================================

This produces an infinite loop like:
=======================
woken with task b'init'
going to sleep, will wake to b'read'
woken with task b'init'
going to sleep, will wake to b'read'
=======================

Note, before the board enters deepsleep, the memory appears to have been set to 'read', but upon waking it is always found to be 'init'. Very frustrating!

I have only encountered this when going to sleep immediately after writing, but it does seem to be a bug. Ideas, anyone?

g-sam
Posts: 6
Joined: Sun Jun 04, 2017 10:12 am

Re: ESP8266 RTC memory ?

Postby g-sam » Mon Jul 10, 2017 3:55 pm

I have figured out that the problem with the code above has nothing to do with RTC memory, but rather with esp.deepsleep. The code continues to run after calling the latter, so the memory is getting set back to 'init'. I could fix it by adding time.sleep(1) after the call to deepsleep. This seems counterintuitive, though -- and is that behaviour documented anywhere?

User avatar
deshipu
Posts: 1190
Joined: Thu May 28, 2015 5:54 pm

Re: ESP8266 RTC memory ?

Postby deshipu » Fri Jul 14, 2017 10:30 am

Nothing gets executed after the deepsleep. The only way to exit deepsleep is to reset the board, and of course the code runs from the beginning then.

g-sam
Posts: 6
Joined: Sun Jun 04, 2017 10:12 am

Re: ESP8266 RTC memory ?

Postby g-sam » Sat Jul 15, 2017 8:47 pm

So I would have expected. But then what is wrong with the code above, and why does adding a time.sleep after the deepsleep fix the problem?

cefn
Posts: 58
Joined: Tue Aug 09, 2016 10:58 am

Re: ESP8266 RTC memory ?

Postby cefn » Sun Jul 16, 2017 4:11 pm

Anecdotally I seem to have seen code running after machine.reset()

See
Interestingly the text "Visiting box 3" is actually from a few lines later than the machine.reset() request, suggesting that things are running on for some reason.
from viewtopic.php?f=16&t=3582&p=20784&hilit=visiting#p20784

Is reset() or deepsleep() perhaps something which is scheduled to run, rather than run immediately?


Who is online

Users browsing this forum: No registered users and 3 guests