Saving circular buffer in flash memory of esp32

aneeshp123
Posts: 6
Joined: Thu Jun 05, 2025 10:18 am

Saving circular buffer in flash memory of esp32

Postby aneeshp123 » Fri Jun 06, 2025 11:41 am

We are making a project where we are supposed to store sensor readings in a circular buffer of 1000 sensor readings in the flash memory. What should be the approach?

HAD1406
Posts: 12
Joined: Thu Jun 05, 2025 10:16 am

Re: Saving circular buffer in flash memory of esp32

Postby HAD1406 » Mon Jun 09, 2025 12:55 pm

Please reply as soon as possible.

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Saving circular buffer in flash memory of esp32

Postby MicroController » Thu Jun 12, 2025 7:23 am

Approach:

if (isBufferFull()) {
deleteOldestEntries();
}
appendNewEntry();

Options:
a) Use a file system and store the data in files - may be the easiest way but also the most inefficient.
b) Use the partitions and flash API to write directly to flash, rotating writes and erases in a dedicated partition of at least 2 pages.

Don't try and use the NVS API. It's not made for this scenario, and as others have already found out may work somewhat but clumsy at best.

Who is online

Users browsing this forum: Applebot, Bytespider, PerplexityBot and 16 guests