Go Down

Topic: ESP12E: Save Data into Flash Memory (Read 13898 times) previous topic - next topic

matt777

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?

pert

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:
https://github.com/esp8266/Arduino/blob/master/doc/libraries.rst#eeprom

As for the lifetime, the ESP8266 datasheet:
http://espressif.com/sites/default/files/documentation/0a-esp8266ex_datasheet_en.pdf
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.

matt777

#2
Jul 26, 2017, 12:27 pm Last Edit: Jul 26, 2017, 12:35 pm by matt777
Perfect, exactly what i was looking for.
Quote
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.

pert

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.

Riva

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
Don't PM me for help as I will ignore it.

matt777

#5
Jul 26, 2017, 07:51 pm Last Edit: Jul 26, 2017, 07:59 pm by matt777
Yeah,
Quote
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.

Riva

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.
Don't PM me for help as I will ignore it.

Go Up