SPIFFS open problems

Hello,
I’m working with a Adafruit Feather HUZZAH ESP8266 and would like to transfer my web app to the ESP8266 with STIFFS, but when I want to make a:
File root = STIFFS.open("/");
I have the following errors (I’m using VSCode):

no instance of overloaded function “fs::FS::open” matches the argument list – argument types are: (const char [2]) – object type is: fs::FS:

conversion from ‘fs::Dir’ to non-scalar type ‘fs::File’ requested

I include: include <ESPAsyncWebServer.h>, <SPIFFSEditor.h> (because if I included just SPIFFS.h, I had an error) and <FS.h>
I don’t why it doesn’t work.
Thanks

This makes sense since / is the root directory so the return value should be a directory?

Anyways can you share your exact platformio.ini and code for reproduction?

Yes:

[env:huzzah]
platform = espressif8266
board = huzzah
framework = arduino

monitor_speed = 115200

lib_deps =
  ESP Async WebServer
  ESPAsyncTCP

But do you think my include are correct?

And your main code? EIther here enclosed with tripple backticks blocks or pastebin does fine

Also your IDE is VSCode right?

#include <Arduino.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFSEditor.h>
#include <FS.h>

const char *ssid = "ION-303";
const char *password = "censoredpassword";

const int led = 0;

AsyncWebServer server(80);

void setup() {
    //----------------------------------------------------Serial
  Serial.begin(115200);
  while(!Serial){}
  Serial.println("\n");

  //----------------------------------------------------GPIO
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);

    //----------------------------------------------------SPIFFS
  if(!SPIFFS.begin())
  {
    Serial.println("Erreur SPIFFS...");
    return;
  }

  File root = SPIFFS.open("/");
  File file = root.openNextFile();

    while(file)
  {
    Serial.print("File: ");
    Serial.println(file.name());
    file.close();
    file = root.openNextFile();
  }

    //----------------------------------------------------WIFI
  WiFi.begin(ssid, password);
	Serial.print("Tentative de connexion...");
	
	while(WiFi.status() != WL_CONNECTED)
	{
		Serial.print(".");
		delay(100);
	}
	
	Serial.println("\n");
	Serial.println("Connexion etablie!");
	Serial.print("Adresse IP: ");
	Serial.println(WiFi.localIP());

  //----------------------------------------------------SERVER
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/index.html", "text/html");
  });

  server.on("/w3.css", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/w3.css", "text/css");
  });

  server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/script.js", "text/javascript");
  });

  server.on("/on", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    digitalWrite(led, HIGH);
    request->send(200);
  });

  server.on("/off", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    digitalWrite(led, LOW);
    request->send(200);
  });

  server.begin();
  Serial.println("Serveur actif!");
}

void loop() {
  // put your main code here, to run repeatedly:
}

Yes I’m using VSCode
Thanks

Yes the calling code is wrong. As you can see with the SPIFFS class which derives from FS (filesystem):

There is either uses File open(const char* path, const char* mode); or Dir openDir(const char* path);. But you’re using it here as File root = SPIFFS.open("/"); for which there is no overload. What you wanted to do is probably like in this unit test

(or also here)

But then you need to write File root = SPIFFS.open("/", "r");

1 Like

It’s working, thank you very much for your help!

1 Like