Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Jep
#53774 Hi guys,

I'm using a NodeMCU board with embedded 12E.
I need a way to store short data that can be read back once the board has been rebooted.
So I tried to use File System but could not even pass this instruction: SPIFFS.begin();

If I use the following code, the program seems to always be stuck in the "begin" function :cry:
Nothing executes after that!

Code: Select allbool ok = SPIFFS.begin();
  if (ok) {
    Serial.println("OK");
  }
  else {
    Serial.println("KO");
  }


Any idea??
By the way, if I just need to store short data (let's say a character) on FS, would it be possible (or simpler) to use EEPROM? What's the best practice?

Thanks :D
User avatar
By rudy
#53820 There is an example sketch that uses RTC memory. It can be used for storage between boots. Not power cycles though. I tried the example and it worked.
https://github.com/esp8266/Arduino/blob ... Memory.ino


EEPROM sample sketches can be found here -
https://github.com/esp8266/Arduino/tree ... M/examples
User avatar
By rudy
#53822 Try this

Code: Select all// EEPROM Write then read

#include <ESP8266WiFi.h>
#include <EEPROM.h>

byte value;

void setup()
{
  WiFi.mode(WIFI_OFF);
 
  Serial.begin(115200);
  Serial.println();
   
  EEPROM.begin(512);

// remove comment to write
/*
//EEPROM.write(addr, val);
  EEPROM.write(0, 12);       
  EEPROM.write(1, 34);
  EEPROM.write(2, 56);
  EEPROM.write(3, 78);
  EEPROM.write(4, 90);
  EEPROM.write(5, 111);
  EEPROM.write(6, 222);
  EEPROM.write(7, 0);   
  EEPROM.commit();   
*/

  Serial.println();
 
  for (int i = 0; i < 14; i++) {
    value=EEPROM.read(i);
  Serial.print(i);
  Serial.print("\t");
  Serial.print(value, DEC);
  Serial.println();   
  }
   
}

void loop()
{
}
User avatar
By Jep
#53835 Thanks rudy ;)
According to the code comments it seems that RTC memory only works between deep sleep boots. I need a solution that works during power cycles also. EEPROM should be the solution then.

However I still don't understand why FS "begin" does not work ...
Do we have to call SPIFFS.format() before mounting FS with SPIFFS.begin() when first using FS?
I found this in the SPIFFS doc :
Formats the file system. May be called either before or after calling begin. Returns true if formatting was successful.