Per MicroPython Zeichenketten ins NVRAM des FiPy speichern

Einleitung

Bisher konnte man über Pycom MicroPython leider nur Zahlen ins NVRAM/NVS des ESP32 speichern. Das lag an der Software. In den Release Notes zur aktuellsten Version v1.20.0.rc11 der Pycom Firmware findet sich jedoch recht frisch die langersehnte Ergänzung.

Dokumentation

Hier die aktuelle Dokumentation.

https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html

Introduction

Non-volatile storage (NVS) library is designed to store key-value pairs in flash. This sections introduces some concepts used by NVS.

Underlying storage

Currently NVS uses a portion of main flash memory through spi_flash_{read|write|erase} APIs. The library uses the all the partitions with data type and nvs subtype. […]

Future versions of this library may add other storage backends to keep data in another flash chip (SPI or I2C), RTC, FRAM, etc.

NVS works best for storing many small values, rather than a few large values of type ‘string’ and ‘blob’. If storing large blobs or strings is required, consider using the facilities provided by the FAT filesystem on top of the wear leveling library.

Keys and values

NVS operates on key-value pairs. Keys are ASCII strings, maximum key length is currently 15 characters. Values can have one of the following types:

  • integer types: uint8_t , int8_t , uint16_t , int16_t , uint32_t , int32_t , uint64_t , int64_t
  • zero-terminated string
  • variable length binary data (blob)

Note

String values are currently limited to 4000 bytes. This includes the null terminator. Blob values are limited to 508000 bytes or (97.6% of the partition size - 4000) bytes whichever is lower.