How to save data (over deep sleep) permanently ? (...
# help
k
I want to save settings, states, ... and recover them after restart.
k
Hi @kaxori. You can store such data in flash or RTC memory.
RTC memory is a bit tricky because it is cleared if you power-cycle or reset -- but it does survive deep sleeps.
If you really want "permanent", you should look at flash.
Toit comes with support for storage buckets backed by flash or RTC memory.
k
Do you have examples ready?
k
https://github.com/toitlang/toit/blob/master/tests/storage_test.toit <-- this might be a bit rich, but it covers most of the functionality.
Here is a short example:
Copy code
import system.storage
main:
  bucket := storage.Bucket.open --flash "my-data-bucket"
  try:
    value := bucket.get "my-key"
    print "existing = $value"
    if value is int: value = value + 1
    else: value = 0
    bucket["my-key"] = value
  finally:
    bucket.close
k
👍🏻 thank you for your fast answer