NVS("label").commit() doubt #12756
nastiliano
started this conversation in
General
Replies: 1 comment 1 reply
-
From some tests I did, it seems that the However, it is safer to do a MicroPython v1.22.0-preview.1.g523284777.dirty on 2023-10-06; ESP32 DEVK1 with ESP32
>>> import esp32
>>> nvsa = esp32.NVS('A')
D (22878) nvs: nvs_open_from_partition A 1
>>> buf = bytearray(20)
>>> nvsa.set_blob('a', 'The key was an a')
D (161578) nvs: nvs_set_blob a 16
>>> nvsa.set_blob('b', 'The next key is a b')
D (187208) nvs: nvs_set_blob b 19
>>> nvsa.get_blob('a',buf)
D (197768) nvs: nvs_get_str_or_blob a
16
>>> buf
bytearray(b'The key was an a\x00\x00\x00\x00')
>>> nvsa.get_blob('b',buf)
D (211618) nvs: nvs_get_str_or_blob b
19
>>> buf
bytearray(b'The next key is a b\x00')
>>> from machine import reset
>>> reset()
..... machine.reset() ......
>>> import esp32
>>> nvsa = esp32.NVS('A')
D (46288) nvs: nvs_open_from_partition A 1
>>> buf = bytearray(20)
>>> nvsa.get_blob('a',buf)
D (60388) nvs: nvs_get_str_or_blob a
16
>>> nvsa.get_blob('a',buf)
D (85758) nvs: nvs_get_str_or_blob a
16
>>> buf
bytearray(b'The key was an a\x00\x00\x00\x00')
>>> nvsa.get_blob('b',buf)
D (121888) nvs: nvs_get_str_or_blob b
19
>>> buf
bytearray(b'The next key is a b\x00')
>>> nvsb = esp32.NVS('B')
D (663308) nvs: nvs_open_from_partition B 1
>>> nvsb.set_blob('a', 'Hello there!')
D (734618) nvs: nvs_set_blob a 12
.... POWER OFF ....
>>> import esp32
>>> nvsa = esp32.NVS('A')
D (20388) nvs: nvs_open_from_partition A 1
>>> nvsb = esp32.NVS('B')
D (26038) nvs: nvs_open_from_partition B 1
>>> buf = bytearray(20)
>>> nvsa.get_blob('a',buf)
D (80728) nvs: nvs_get_str_or_blob a
16
>>> buf
bytearray(b'The key was an a\x00\x00\x00\x00')
>>> nvsa.get_blob('b',buf)
D (95198) nvs: nvs_get_str_or_blob b
19
>>> buf
bytearray(b'The next key is a b\x00')
>>> nvsb.get_blob('a',buf)
D (118068) nvs: nvs_get_str_or_blob a
12
>>> buf
bytearray(b'Hello there! is a b\x00')
>>> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone.
I read the documentation about ESP32 and NVS (Non-volatile Storage) and it says that:
"Changes to NVS need to be committed to flash by calling the commit method. Failure to call commit results in changes being lost at the next reset."
But my doubt is if I must use "commit()" after every ".set" operation or I can define:
And make, for example, 10 write operations and finally close with a "commit" operation before reset the device.
Thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions