guild icon
Toit
#How to save data (over deep sleep) permanently ? (solved)
Thread channel in help
kaxori
kaxori 07/05/2023 08:39 AM
I want to save settings, states, ... and recover them after restart.(edited)
bitphlipphar
bitphlipphar 07/05/2023 08:39 AM
Hi @kaxori. You can store such data in flash or RTC memory.
bitphlipphar
bitphlipphar 07/05/2023 08:40 AM
RTC memory is a bit tricky because it is cleared if you power-cycle or reset -- but it does survive deep sleeps.
bitphlipphar
bitphlipphar 07/05/2023 08:40 AM
If you really want "permanent", you should look at flash.
bitphlipphar
bitphlipphar 07/05/2023 08:41 AM
Toit comes with support for storage buckets backed by flash or RTC memory.
kaxori
kaxori 07/05/2023 08:41 AM
Do you have examples ready?
bitphlipphar
bitphlipphar 07/05/2023 08:41 AM
https://github.com/toitlang/toit/blob/master/tests/storage_test.toit <-- this might be a bit rich, but it covers most of the functionality.
Program your microcontrollers in a fast and robust high-level language. - toit/tests/storage_test.toit at master ยท toitlang/toit
bitphlipphar
bitphlipphar 07/05/2023 08:44 AM
Here is a short example:
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
kaxori
kaxori 07/05/2023 08:45 AM
:๐Ÿ‘๐Ÿป: thank you for your fast answer
๐Ÿ‘ทโ€โ™‚๏ธ1
10 messages in total