Arduino: Make SD Class be able to coexist with SPIFFS

Created on 28 Jan 2016  路  6Comments  路  Source: esp8266/Arduino

we should rework this to use the same API (will look into it)
but this is for now
https://github.com/me-no-dev/Arduino/commit/72c2c3f4e2a0c4de29ce5f946417aed6130748d5

Most helpful comment

Do you have an example on how to use the two file systems side by side? Something like open, access and close a file on SPIFFs then on SD card.

Edit:
I figured it out and to save others the hassle, here is a simple example:

#define FS_NO_GLOBALS //allow spiffs to coexist with SD card, define BEFORE including FS.h
#include <FS.h> //spiff file system

//accessing SPIFFS files, add 'fs::' in front of the file declaration, the rest is done as usual:
   fs::File file = SPIFFS.open(path, "r");  //add the namespace 
   size_t sent = server.streamFile(file, contentType); //stream file to webclient
   file.close();

//accessing SD card files is done the usual way:
 File dataFile = SD.open(filename, FILE_WRITE); //create the file
      if (dataFile) {
        String header = "Logfile created at "  + getTimeString();
        dataFile.println(header);
      }
      dataFile.close();

All 6 comments

hi, if this is to be done at some point, maybe it s worth adding long file names as well and this suggestion here
https://github.com/esp8266/Arduino/issues/641
SdFat lib with LFN support https://github.com/tannewt/SdFat

Fixed in 43fb139

Do you have an example on how to use the two file systems side by side? Something like open, access and close a file on SPIFFs then on SD card.

Edit:
I figured it out and to save others the hassle, here is a simple example:

#define FS_NO_GLOBALS //allow spiffs to coexist with SD card, define BEFORE including FS.h
#include <FS.h> //spiff file system

//accessing SPIFFS files, add 'fs::' in front of the file declaration, the rest is done as usual:
   fs::File file = SPIFFS.open(path, "r");  //add the namespace 
   size_t sent = server.streamFile(file, contentType); //stream file to webclient
   file.close();

//accessing SD card files is done the usual way:
 File dataFile = SD.open(filename, FILE_WRITE); //create the file
      if (dataFile) {
        String header = "Logfile created at "  + getTimeString();
        dataFile.println(header);
      }
      dataFile.close();

full code please :/

This not really works for me. The namespace error disappeared but the read / write experience seams to not working for me. In your code you dont use any include SD.h is it a mistake or...? And if it missed where is it suppose to go? Before? After? Thanks

@duckylock you may try https://github.com/esp8266/Arduino/pull/5525 (soon to be merged)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tiestvangool picture tiestvangool  路  3Comments

mark-hahn picture mark-hahn  路  3Comments

markusschweitzer picture markusschweitzer  路  3Comments

Marcelphilippeandrade picture Marcelphilippeandrade  路  3Comments

SmartSouth picture SmartSouth  路  3Comments