Esp8266 SPIFFS empty

Hello,

I am struggiling with SPIFFS a bit.
Here my platformio.ini:

[env:esp8622]
platform = espressif8266@2.6
framework = arduino
board = esp12e
board_build.filesystem = spiffs
monitor_speed = 115200
lib_deps =
    me-no-dev/ESP Async WebServer@^1.2.3
    ayushsharma82/AsyncElegantOTA@^2.2.6
    knolleary/PubSubClient@^2.8
    adafruit/Adafruit Fingerprint Sensor Library@^2.0.7
    intrbiz/Crypto@^1.0.0
    vshymanskyy/Preferences  #otherwise Preferences.h was missing  
    ESP8266wifi

lib_ldf_mode = deep
build_flags =   -Wl,-Teagle.flash.4m2m.ld

And in the code:

  if(!SPIFFS.begin()){
    Serial.println("An Error has occurred while mounting SPIFFS. Possibly you need to format the FS. See https://github.com/espressif/arduino-esp32/issues/638");
    //SPIFFS.format()
    return;
  }
  String str = "";
  Serial.println("SPIFFS begin successful. Listing Directories");
  Dir dir = SPIFFS.openDir("/");
  while (dir.next()) {
      str += dir.fileName();
      str += " / ";
      str += dir.fileSize();
      str += "\r\n";
  }
  Serial.print(str);
  Serial.println("SPIFFS begin successful. Listing Directories END.");

in my /data/ dir, I have four files (css and html).

I run Build and then Upload under General and then Build Filesystem and Upload Filesystem Image under Platform.
The building of the FS looks good:

Building file system image from 'data' directory to .pio\build\esp8622\spiffs.bin
/bootstrap.min.css
/index.html
/settings.html
/wificonfig.html

Now, I would expect this output:

SPIFFS begin successful. Listing Directories
/bootstrap.min.css
/index.html
/settings.html
/wificonfig.html
SPIFFS begin successful. Listing Directories END.

but I only get

SPIFFS begin successful. Listing Directories
SPIFFS begin successful. Listing Directories END.

What am I missing?

Best regards,
Hendrik

This platform version is old, is it the same behavior with @4.0.1?

Hello,

thanks for your hint. With that, I do not even get that far:

src\SettingsManager.cpp: In member function 'bool SettingsManager::loadWifiSettings()':
src\SettingsManager.cpp:5:17: error: control reaches end of non-void function [-Werror=return-type]
    5 |     Preferences preferences;
      |                 ^~~~~~~~~~~
src\SettingsManager.cpp: In member function 'bool SettingsManager::loadAppSettings()':
src\SettingsManager.cpp:17:17: error: control reaches end of non-void function [-Werror=return-type]
   17 |     Preferences preferences;
      |                 ^~~~~~~~~~~
cc1plus.exe: some warnings being treated as errors
*** [.pio\build\esp8622\src\SettingsManager.cpp.o] Error 1
In file included from src\main.cpp:10:

and later

src\main.cpp:293:30: error: no matching function for call to 'fs::FS::open(const char [2])'
  293 |   File root = SPIFFS.open("/");

Best regards,
Hendrik

I think this has to be SPIFFS.openDir("/"); now (source).

Can you create a new project with nothing but the test SPIFFS code active? This avoids the compile errors from unrelated code.

Hello,

sure.
Here the complete code:

#include <FS.h>

void setup()
{
Serial.begin(115200);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
if(!SPIFFS.begin()){
    Serial.println("An Error has occurred while mounting SPIFFS. Possibly you need to format the FS. See https://github.com/espressif/arduino-esp32/issues/638");
    //SPIFFS.format()
    return;
  }
  String str = "";
  Serial.println("SPIFFS begin successful. Listing Directories");
  Dir dir = SPIFFS.openDir("/");
  while (dir.next()) {
      str += dir.fileName();
      str += " / ";
      str += dir.fileSize();
      str += "\r\n";
  }
  Serial.print(str);
  Serial.println("SPIFFS begin successful. Listing Directories END.");

}

The result on the serial port:

SPIFFS begin successful. Listing Directories
SPIFFS begin successful. Listing Directories END.

Just to make sure: Does it make a difference, in what order the code is flashed (first Filesystem image or first code)?

Best regards,
Hendrik

Hm… I got it working now.

PIFFS begin successful. Listing Directories
/bootstrap.min.css / 121205
/index.html / 5062
/settings.html / 5757
/wificonfig.html / 2814
SPIFFS begin successful. Listing Directories END.

I had forgotten the build_flags = -Wl,-Teagle.flash.4m2m.ld
In my test-project.

So… Where are we now: with my test-project and 4.0.1 my code for the SPIFFS does work.

So, now I need help to get preferences running with this version (see compile error above).

Should I start a new thread for that?

Best regards,
Hendrik

In recent versions, the board_build.ldscript = .. should be used to set the linker script, maybe that’s the key here. I’d recommend that instead of the build_flags with -T.

Can you post the affected sections of code here? Should be a quick fix, compiler says there’s a function that has to return something (not void) but there are code paths at whose end there is no return <some value>;.

Hello,

thanks.
So instead build_flags = -Wl,-Teagle.flash.4m2m.ld
I would use
board_build.ldscript = eagle.flash.4m.ld

Correct?

The SettingsManager.cpp is this one FingerprintDoorbell/SettingsManager.h at master · henfri/FingerprintDoorbell · GitHub

Best regards,
Hendrik

Both these functions don’t hit a return true/false; when the if path is taken. Did you mean to return true; in that case?

Exactly.

Hello,

thanks, that helped.
It is a bit mis-leading that the compiler pointed at the line Preferences preferences;.
I will have to get used to that. In the python world, I found it easier to find the cause of an error.

I will check, if the SPFFS is working tomorrow (no access to the hardware now).

Best regards,
Hendrik