I am migrating one project from PIC to ESP32 and I have the following question regarding data storage.
At the moment I use an external memory in the PIC to store some statistical data. The memory is divided in 366 chunks, one per day of the year, where I save what the equipment consumes every day.
So let's say position 0x00 is January 1st. When the equipment needs to save data there it just first reads the current value, adds the new value and save the updated value to the same position 0x00. It just goes like this:
- New value to save is 125
- Reads what is already in 0x00
- Ads 125 to that
- Save the updated value again to 0x00
I am now trying to do this in ESP32 so I defined a data partition like the following (storage)
Code: Select all
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
storage, data, , , 0x40000,
The problem is, as I understand from this other reply (https://esp32.com/viewtopic.php?t=16229#p61746) that esp_partition_write() makes bits go from 1 to 0 but not viceversa, the only way to go back to 1 is erasing the corresponding chunk through esp_partition_erase_range()
So, how do I update a particular value here by using esp_partition_write() if only the first will really work (when all bits are set to 1)? According to this I should erase first but this seems not to be a good practice since I am gonna wear the memory too fast.
I know in this paticular situation, where it's very simple, I could use NVS system but what if it were not only 366 positions but much larger data map? Should I still use NVS and increase its partition size if needed?
Thank you.