I am able to write NVS values by creating a pre-generate NVS data partition (as binary file) and write it in the esp32 partition. But I am unable to read these values despite there are indeed present in the NVS partition.
The commands I executed are:
1- nvs_partition_gen.py generate mfgdata.csv mfgdata.bin 0x5000
to get the pre-generate NVS data partition from
key,type,encoding,value
customNvs,namespace,,
batterySn,data,u32,65535
smartboxSn,data,u32,65534
test,data,u32,65533
2- parttool.py -p COM24 -b 115200 write_partition --partition-name=nvs --input=mfgdata.bin
to write the new NVS partition
I extracted the NVS partition and indeed, the value was there:
00000020: aaff ffff ffff ffff ffff ffff ffff ffff ................
00000030: ffff ffff ffff ffff ffff ffff ffff ffff ................
00000040: 0001 01ff ba23 32a8 6375 7374 6f6d 4e76 .....#2.customNv
00000050: 7300 0000 0000 0000 01ff ffff ffff ffff s...............
00000060: 0104 01ff 24f9 ba27 6261 7474 6572 7953 ....$..'batteryS
00000070: 6e00 0000 0000 0000 ffff 0000 ffff ffff n...............
00000080: 0104 01ff 6a8e f27b 736d 6172 7462 6f78 ....j..{smartbox
00000090: 536e 0000 0000 0000 feff 0000 ffff ffff Sn..............
000000a0: 0104 01ff a69b 9df6 7465 7374 0000 0000 ........test....
000000b0: 0000 0000 0000 0000 fdff 0000 ffff ffff ................
000000c0: ffff ffff ffff ffff ffff ffff ffff ffff ...............
The problem is that I am not able to read these value. Before I wrote batterySn value thru Preferences
API thru a bluetooth app.
I extracted NVS partition after setting batterySn thr the app and I get this:
00000040: 0001 01ff ba23 32a8 6375 7374 6f6d 4e76 .....#2.customNv
00000050: 7300 0000 0000 0000 01ff ffff ffff ffff s...............
00000060: 0104 01ff 24f9 ba27 6261 7474 6572 7953 ....$..'batteryS
00000070: 6e00 0000 0000 0000 ffff 0000 ffff ffff n...............
00000080: 0104 01ff 6a8e f27b 736d 6172 7462 6f78 ....j..{smartbox
00000090: 536e 0000 0000 0000 feff 0000 ffff ffff Sn..............
000000a0: 0104 01ff a69b 9df6 7465 7374 0000 0000 ........test....
.
.
.
00002380: 0204 01ff fd7a be81 7570 7469 6d65 0000 .....z..uptime..
00002390: 0000 0000 0000 0000 3c00 0000 ffff ffff ........<.......
000023a0: 0204 01ff 4bb2 b35d 6261 7474 6572 7953 ....K..]batteryS
000023b0: 6e00 0000 0000 0000 0100 0000 ffff ffff n...............
000023c0: 0204 01ff eab6 692c 7570 7469 6d65 0000 ......i,uptime..
000023d0: 0000 0000 0000 0000 7800 0000 ffff ffff ........x.......
My customNvs value are still there and there is batterySn value but in a different place. Only the second batterySn value can be read.
I tried to add a new argument to the write command like so:
parttool.py -p COM24 -b 115200 --partition-table-offset 0x9000 write_partition --partition-name=nvs --input=mfgdata.bin
Because my customNVS partition have an offset of 0x9000
but by doing that I get an error:
File "C:\ESP-IDF\components\partition_table\parttool.py", line 368, in <module>
main()
File "C:\ESP-IDF\components\partition_table\parttool.py", line 337, in main
target = ParttoolTarget(**target_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ESP-IDF\components\partition_table\parttool.py", line 119, in __init__
partition_table = gen.PartitionTable.from_binary(b)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ESP-IDF\components\partition_table\gen_esp32part.py", line 231, in from_binary
result.append(PartitionDefinition.from_binary(data))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\ESP-IDF\components\partition_table\gen_esp32part.py", line 381, in from_binary
res.name = res.name.decode()
^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Please tell me if my explanation is not clear enough or my process to write values in NVS partition is wrong.
My custom partition:
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000
otadata, data, ota, 0xE000, 0x2000
app0, app, ota_0, 0x10000, 0x2A0000
app1, app, ota_1, 0x2B0000, 0x2A0000
ffat, data, fat, 0x550000, 0x2B0000