Persistent data with deepsleep

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Posts: 1
Joined: Sat Nov 16, 2019 7:49 pm

Persistent data with deepsleep

Post by CharlesG » Sat Nov 16, 2019 8:01 pm

The specs for both ESP32 and ESP8266 talk about RTC memory for data retention between deep sleep instances. This is useful for counts, previous sensor values etc.

I have found many useful articles on exploiting this with Arduino C code but I have found nothing to tell me how to do this with MicroPython. Am I bad searcher or does it not exist?

I have read of using flash memory but flash memory is reputed to have limited write cycles. Or am I wrong on this too?

Thanks in advance for any help on this.

User avatar
Posts: 4037
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Re: Persistent data with deepsleep

Post by pythoncoder » Sun Nov 17, 2019 9:03 am

Flash memory does have a limitation on the number of write cycles, typically on the order of 10,000.

The following works on an ESP8266:

Code: Select all

import machine
import ujson
rtc = machine.RTC()
d = {1:'one', 2:'two'}  # Example data to save
rtc.memory(ujson.dumps(d))  # Save in RTC RAM

r = ujson.loads(rtc.memory())  # Restore from RTC RAM
# r == {2: 'two', 1: 'one'}
Peter Hinch

Post Reply