Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Return None for unknown nvs_get keys #74

Closed
wants to merge 6 commits into from
Closed

Conversation

dbrgn
Copy link

@dbrgn dbrgn commented Sep 28, 2017

Currently the nvs_get function will initialize unknown values to 0. This results in two problems:

  • Every read on an unknown key will result in a write.
  • It is not possible to discern a value that has been set to 0, and a value that does not exist.

By returning None for unknown values, discerning missing and 0 values becomes possible.

Note: There are some additional problems with the nvs functionality:

  • NVRAM values cannot currently be erased. That's a problem because NVRAM could fill up, rendering the nvs_* functions useless without compiling custom firmware
  • The error handling is lacking. For example, according to the docs, there are 5 different error codes for NVRAM write problems. It would be good if these were passed to the user, probably via exceptions.
  • Note also that right now (even with this fix) a uninitialized variable will be passed to mp_obj_new_int if nvs_get_u32 returns an error code other than ESP_ERR_NVS_NOT_FOUND.

Note: This would of course have to be mentioned in the release notes, since it's a breaking change (the return type is changed).

robert-hh and others added 6 commits September 1, 2017 21:22
ustruct: Pull in ustruct module from the Micropython.org tree
New IDF needs a new toolchain
Currently the `nvs_get` function will initialize unknown values to 0.
This results in two problems:

* Every read on an unknown key will result in a write.
* It is not possible to discern a value that has been set to 0, and a
  value that does not exist.

By returning `None` for unknown values, discerning missing and 0 values
becomes possible.
@danicampora
Copy link

Merged long ago, thanks. New API functions were added to erase the NRAM area in case it gets full.

Xykon pushed a commit that referenced this pull request Feb 4, 2020
X-Ryl669 pushed a commit to X-Ryl669/pycom-micropython-sigfox that referenced this pull request May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants