SD card and SPIFFS at tha same time. Just can't get past this

Hello all

I have a project that needs to use the SD card as well as SPIFFS. There is known conflict of name File being declared in both library's.

I found a few pages about this, and tried the solution suggested here:

But, that does not work for me. I still get the error.
This is the snippet of code that handles my SPIFFs files (I believe), and I have added the fs:: as suggested.
Still doesn't compile

bool handleFileRead(String path) {                                                                                         // send the right file to the client (if it exists)
  Serial.println("handleFileRead: " + path);
  if (path.endsWith("/")) path += "index.html";                                                                            // If a folder is requested, send the index file
  String contentType = getContentType(path);                                                                               // Get the MIME type
  String pathWithGz = path + ".gz";
  if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {                                                                  // If the file exists, either as a compressed archive, or normal
    if (SPIFFS.exists(pathWithGz))                                                                                         // If there's a compressed version available
      path += ".gz";                                                                                                       // Use the compressed verion
    fs::File file = SPIFFS.open(path, "r");                                                                                    // Open the file
    size_t sent = server.streamFile(file, contentType);                                                                    // Send it to the client
    file.close();                                                                                                          // Close the file again
    Serial.println(String("\tSent file: ") + path);
    return true;
  }
  Serial.println(String("\tFile Not Found: ") + path);                                                                     // If the file doesn't exist, return false
  return false;
}

Anyone have any suggestions?

I wish someone would make an I2C SD card module! Would save quite a lot of grief

Please post a complete sketch that illustrates the problem

Does LittleFS cause the same problem as SPIFFS ?

OK, I will have to 'tidy up' the code then. Its a debugging mess

Don't know what LittleFS is? GoogleTime

Don't know what LittleFS is

It is the replacement for SPIFFS now that SPIFFS has been deprecated

Whether it will do what you want I cannot say

:confused: Just as you get your head around something, they change it.
Nothing comes up in Library manager (for esp8266, only for ESP32). I'll have to go looking for the library and an example then

This may be of interest #203 SPIFFS vs LITTLEFS for ESP32✅ & ESP8266✅ (not Arduino UNO❌) - YouTube

I just watched that Bob - thanks
The library he uses is for the ESP32 however. I still have not found one for the ESP8266 yet

Well apparently all you need to change all instances of SPIFFS to LittleFS.
Did that, it complies but now can't find any files. It says SPIFFS doesn't support directories, yet my files are in directories and it worked fine.

Trouble is, I don't really understand all of the SPIFFS file system (it's lifted from a piece of code online), so I am not exactly sure what the problem is.

Anyway, two options... go back to SPIFFS, as at least that works..... or tidy my code, remove any bits that should not be seen by others and post it in here. Hmm

It says SPIFFS doesn't support directories, yet my files are in directories and it worked fine.

I believe that SPIFFS "directories" are really just filenames so although /dir1/file1.txt may look like a file named file1.txt in a directory named /dir1 it is, in fact, a file named /dir1/file1.txt

I may be wrong, but using SPIFFS can you list the files in a directory ?

Its all working with LittleFS now.
Before, I had sub directories in my data folder for JS,CSS,IMG,TXT etc.

Now, they are all just lumped into the data folder together. Not as tidy in my opinion, and if I spent some time on it, I could probably work out why I have lost the sub-file ability.
I also had to remove the directory addresses from my index.html file.

I have to say, its actually slower/same loading the files to the webpage than the original SPIFFS, so I have not seen any advantage yet.

My LittleFS initialisation is:

void startLittleFS() {                                                                                                     // Start the LittleFS and list all contents
  LittleFS.begin();
  Serial.println("LittleFS started. Contents:");
  {
    Dir dir = LittleFS.openDir("/");
    while (dir.next()) {                                                                                                   // List the file system contents
      String fileName = dir.fileName();
      size_t fileSize = dir.fileSize();
      Serial.printf("\tFS File: %s, size: %s\r\n", fileName.c_str(), formatBytes(fileSize).c_str());
    }
    Serial.printf("\n");
  }
}

This fails to find sub directories within the data folder

My original SPIFFS serving code is:

bool handleFileRead(String path) {                                                                                         // send the right file to the client (if it exists)
  Serial.println("handleFileRead: " + path);
  if (path.endsWith("/")) path += "index.html";                                                                            // If a folder is requested, send the index file
  String contentType = getContentType(path);                                                                               // Get the MIME type
  String pathWithGz = path + ".gz";
  if (LittleFS.exists(pathWithGz) || LittleFS.exists(path)) {                                                              // If the file exists, either as a compressed archive, or normal
    if (LittleFS.exists(pathWithGz))                                                                                       // If there's a compressed version available
      path += ".gz";                                                                                                       // Use the compressed verion
    File file = LittleFS.open(path, "r");                                                                                  // Open the file
    size_t sent = server.streamFile(file, contentType);                                                                    // Send it to the client
    file.close();                                                                                                          // Close the file again
    Serial.println(String("\tSent file: ") + path);
    return true;
  }
  Serial.println(String("\tFile Not Found: ") + path);                                                                     // If the file doesn't exist, return false
  return false;
}

I will decode it line by line later and see if I can determine the issue.

Hello all

Rather than write out the entire project again, I thought it best to continue this thread.

I have LittleFS working well. Never got it to work alongside an SD card due to conflicts, but that is a problem for another day.

So, we have various two way comms between my ESP8266 and the webpage. Gauges, slides, text transmissions etc.

My ESP8266 creates an AP. I log into this AP with the ip address 192.168.1.40.
How do I get it to use a name instead?

I originally thought it was using: WiFi.hostname("NewName");, but this I think is the name your local router sees when it connects to the ESP8266.

So then I thought maybe its: mdnsName = "NewName";

But mDNS fails to run. Apparently it's an issue with WIN 10 or you can't use it when in AP mode?

Any help with guidance on what actually establishes the name in the title bar of the page you have logged into would be very helpful.
Thanks!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.