ESP12E: Save Data into Flash Memory

Hello, i want to save some datas (for example meassurements from sensors, textfiles, logs, etc)I into the 4Mb flash memory of the ESP12E. Such like saving this to the flash memory of an sd card.

Is this possible? How? What about the lifetime of the flash memory?

1 Like

Probably the easiest way to do this is via the ESP8266 core for Arduino's EEPROM library. The ESP8266 actually doesn't have EEPROM so the library uses the flash instead. Although a similar API, the library is slightly different from the stock Arduino EEPROM library in that you need to initialize the EEPROM to your desired size. Also, after writing you must save your changes using either EEPROM.commit() or EEPROM.end() to actually write them to flash. Documentation here:

As for the lifetime, the ESP8266 datasheet:

doesn't mention it but this makes sense because the flash is an external IC on the module but not on the ESP8266 IC. The trick is to either find out what flash IC is used on your module (which may be difficult if it has the metal shield) or to find the datasheet for the module.

Perfect, exactly what i was looking for.

Size can be anywhere between 4 and 4096 byte

.
let's assume my programmcode is 7kb. In this case, the size shouldn't be 4096, right? Something like
4096 bytes - size of program in bytes
Or should i better leave more space? Is this necessary? Like reserving 4000 bytes instead of 4089/4096 bytes.

My understanding is this is using a dedicated section of flash so you don't need to worry about that. If you need more than the 4096 bytes then there are other ways to access the SPIFFS but I think it's a bit more complicated. I haven't tried it because the "EEPROM" section was always plenty for my needs of storing user settings in non-volatile memory.

Probably an easier way to store data would be to use SPIFFS library as you can then use file based access that is pretty similar to SD card access. To download files created in the SFIFFS section you can maybe use a FTP server like this

Yeah,

File f = SPIFFS.open("/f.txt", "w");
if (!f) {
Serial.println("file open failed");
}

truly looks like the sd library. But do i see this right? For uploading datas i have to use the Arduino IDE or FTP or maybe other programs, but i can't upload those directly threw my script (such like sd cards)? There is no SPIFFS.write(); in the library?

But nevermind. I only want to know this just in case. EEPROM is exactly what i need, thanks.

matt777:
Yeah, truly looks like the sd library. But do i see this right? For uploading datas i have to use the Arduino IDE or FTP or maybe other programs, but i can't upload those directly threw my script (such like sd cards)? There is no SPIFFS.write(); in the library?

SPIFFS.open uses the same syntax as fopen so the example you posted in #5 is to open f.txt for writing.