Skip to content
Next Next commit
Deprecate SPIFFS, move examples to LittleFS
SPIFFS has been a great filesystem, but it has significant problems in many cases (and it's also pretty slow). Development seems to have slowed/stopped on the upstream version, and we're not able to provide support or fix the known issues with it as-is. Deprecate SPIFFS variable. Update all examples to use LittleFS instead of SPIFFS. Also, minor cleanup on very old examples which has obsolete delays waiting for the Serial port to come up, or which were stuck at 9600 baud because of their ancient AVR heritage. Fixes #7095
  • Loading branch information
earlephilhower committed May 3, 2020
commit 2e5ee76fffa7619efe282351ea5d16a61ddda354
2 changes: 1 addition & 1 deletion cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ using fs::SPIFFSConfig;
#endif //FS_NO_GLOBALS

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPIFFS)
extern fs::FS SPIFFS;
extern fs::FS SPIFFS __attribute__((deprecated("SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems.")));
#endif

#endif //FS_H
6 changes: 4 additions & 2 deletions cores/esp8266/spiffs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
return flash_hal_read(addr, size, dst);
}



#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

namespace spiffs_impl {

Expand Down Expand Up @@ -149,6 +149,8 @@ extern "C" void spiffs_request_end(void)
SPIFFS.end();
}

#pragma GCC diagnostic pop

#endif // ARDUINO
#endif // !CORE_MOCK

Expand Down
4 changes: 3 additions & 1 deletion cores/esp8266/spiffs_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class SPIFFSImpl : public FSImpl
return false;
}
_cfg = *static_cast<const SPIFFSConfig *>(&cfg);
return true;
return true;
}

bool begin() override
Expand Down Expand Up @@ -356,6 +356,8 @@ class SPIFFSImpl : public FSImpl
std::unique_ptr<uint8_t[]> _cacheBuf;

SPIFFSConfig _cfg;

int _called = 0;
};

#define CHECKFD() while (_fd == 0) { panic(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ unsigned int status = WL_IDLE_STATUS;

void setup() {
delay(1000);
Serial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
Expand Down
3 changes: 0 additions & 3 deletions libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ byte value;
void setup() {
// initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
EEPROM.begin(512);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

/* this can be run with an emulated server on host:
cd esp8266-core-root-dir
cd tests/host
Expand All @@ -27,21 +25,21 @@

void setup() {

USE_SERIAL.begin(115200);
Serial.begin(115200);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
Serial.println();
Serial.println();
Serial.println();

WiFi.begin(STASSID, STAPSK);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
USE_SERIAL.print(".");
Serial.print(".");
}
USE_SERIAL.println("");
USE_SERIAL.print("Connected! IP address: ");
USE_SERIAL.println(WiFi.localIP());
Serial.println("");
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());

}

Expand All @@ -52,29 +50,29 @@ void loop() {
WiFiClient client;
HTTPClient http;

USE_SERIAL.print("[HTTP] begin...\n");
Serial.print("[HTTP] begin...\n");
// configure traged server and url
http.begin(client, "http://" SERVER_IP "/postplain/"); //HTTP
http.addHeader("Content-Type", "application/json");

USE_SERIAL.print("[HTTP] POST...\n");
Serial.print("[HTTP] POST...\n");
// start connection and send HTTP header and body
int httpCode = http.POST("{\"hello\":\"world\"}");

// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] POST... code: %d\n", httpCode);
Serial.printf("[HTTP] POST... code: %d\n", httpCode);

// file found at server
if (httpCode == HTTP_CODE_OK) {
const String& payload = http.getString();
USE_SERIAL.println("received payload:\n<<");
USE_SERIAL.println(payload);
USE_SERIAL.println(">>");
Serial.println("received payload:\n<<");
Serial.println(payload);
Serial.println(">>");
}
} else {
USE_SERIAL.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
}

http.end();
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

// Select the FileSystem by uncommenting one of the lines below

#define USE_SPIFFS
//#define USE_LITTLEFS
//#define USE_SPIFFS
#define USE_LITTLEFS
//#define USE_SDFS

// Uncomment the following line to embed a version of the web page in the code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
1. Creating a secure web server using ESP8266ESP8266WebServerSecure
2. Use of HTTP authentication on this secure server
3. A simple web interface to allow an authenticated user to change Credentials
4. Persisting those credentials through a reboot of the ESP by saving them to SPIFFS without storing them as plain text
4. Persisting those credentials through a reboot of the ESP by saving them to LittleFS without storing them as plain text
*/

#include <FS.h>
#include <LittleFS.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServerSecure.h>

Expand All @@ -23,8 +24,8 @@
const char* ssid = STASSID;
const char* wifi_pw = STAPSK;

const String file_credentials = R"(/credentials.txt)"; //SPIFFS file name for the saved credentials
const String change_creds = "changecreds"; //address for a credential change
const String file_credentials = R"(/credentials.txt)"; // LittleFS file name for the saved credentials
const String change_creds = "changecreds"; // Address for a credential change

//The ESP8266WebServerSecure requires an encryption certificate and matching key.
//These can generated with the bash script available in the ESP8266 Arduino repository.
Expand Down Expand Up @@ -83,7 +84,7 @@ gz5JWYhbD6c38khSzJb0pNXCo3EuYAVa36kDM96k1BtWuhRS10Q1VXk=

ESP8266WebServerSecure server(443);

//These are temporary credentials that will only be used if none are found saved in SPIFFS.
//These are temporary credentials that will only be used if none are found saved in LittleFS.
String login = "admin";
const String realm = "global";
String H1 = "";
Expand All @@ -92,9 +93,9 @@ String authentication_failed = "User authentication has failed.";
void setup() {
Serial.begin(115200);

//Initialize SPIFFS to save credentials
if(!SPIFFS.begin()){
Serial.println("SPIFFS initialization error, programmer flash configured?");
//Initialize LittleFS to save credentials
if(!LittleFS.begin()){
Serial.println("LittleFS initialization error, programmer flash configured?");
ESP.restart();
}

Expand Down Expand Up @@ -187,16 +188,16 @@ void showcredentialpage(){
server.send(200, "text/html", page);
}

//Saves credentials to SPIFFS
//Saves credentials to LittleFS
void savecredentials(String new_login, String new_password)
{
//Set global variables to new values
login=new_login;
H1=ESP8266WebServer::credentialHash(new_login,realm,new_password);

//Save new values to SPIFFS for loading on next reboot
//Save new values to LittleFS for loading on next reboot
Serial.println("Saving credentials.");
File f=SPIFFS.open(file_credentials,"w"); //open as a brand new file, discard old contents
File f=LittleFS.open(file_credentials,"w"); //open as a brand new file, discard old contents
if(f){
Serial.println("Modifying credentials in file system.");
f.println(login);
Expand All @@ -208,12 +209,12 @@ void savecredentials(String new_login, String new_password)
Serial.println("Credentials saved.");
}

//loads credentials from SPIFFS
//loads credentials from LittleFS
void loadcredentials()
{
Serial.println("Searching for credentials.");
File f;
f=SPIFFS.open(file_credentials,"r");
f=LittleFS.open(file_credentials,"r");
if(f){
Serial.println("Loading credentials from file system.");
String mod=f.readString(); //read the file to a String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// Before running, you must download the set of certs using
// the script "certs-from-mozilla.py" (no parameters)
// and then uploading the generated .AR file to SPIFFS or SD.
// and then uploading the generated .AR file to LittleFS or SD.
//
// You do not need to generate the ".IDX" file listed below,
// it is generated automatically when the CertStore object
// is created and written to SD or SPIFFS by the ESP8266.
// is created and written to SD or LittleFS by the ESP8266.
//
// Why would you need a CertStore?
//
Expand Down Expand Up @@ -37,6 +37,7 @@
#include <CertStoreBearSSL.h>
#include <time.h>
#include <FS.h>
#include <LittleFS.h>

#ifndef STASSID
#define STASSID "your-ssid"
Expand Down Expand Up @@ -117,7 +118,7 @@ void setup() {
Serial.println();
Serial.println();

SPIFFS.begin();
LittleFS.begin();
// If using a SD card or LittleFS, call the appropriate ::begin instead

// We start by connecting to a WiFi network
Expand All @@ -138,10 +139,10 @@ void setup() {

setClock(); // Required for X.509 validation

int numCerts = certStore.initCertStore(SPIFFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
int numCerts = certStore.initCertStore(LittleFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
Serial.printf("Number of CA certs read: %d\n", numCerts);
if (numCerts == 0) {
Serial.printf("No certs found. Did you run certs-from-mozilla.py and upload the SPIFFS directory before running?\n");
Serial.printf("No certs found. Did you run certs-from-mozilla.py and upload the LittleFS directory before running?\n");
return; // Can't connect to anything w/o certs!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This script pulls the list of Mozilla trusted certificate authorities
# from the web at the "mozurl" below, parses the file to grab the PEM
# for each cert, and then generates DER files in a new ./data directory
# Upload these to a SPIFFS filesystem and use the CertManager to parse
# Upload these to an on-chip filesystem and use the CertManager to parse
# and use them for your outgoing SSL connections.
#
# Script by Earle F. Philhower, III. Released to the public domain.
Expand Down
2 changes: 0 additions & 2 deletions libraries/ESP8266WiFi/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ BearSSL KEYWORD1
X509List KEYWORD1
PrivateKey KEYWORD1
PublicKey KEYWORD1
CertStoreSPIFFSBearSSL KEYWORD1
CertStoreSDBearSSL KEYWORD1
Session KEYWORD1
ESP8266WiFiGratuitous KEYWORD1

Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/CertStoreBearSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <FS.h>

// Base class for the certificate stores, which allow use
// of a large set of certificates stored on SPIFFS of SD card to
// of a large set of certificates stored on FS or SD card to
// be dynamically used when validating a X509 certificate

namespace BearSSL {
Expand Down
30 changes: 14 additions & 16 deletions libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>

#define USE_SERIAL Serial

#ifndef APSSID
#define APSSID "APSSID"
#define APPSK "APPSK"
Expand All @@ -24,16 +22,16 @@ ESP8266WiFiMulti WiFiMulti;

void setup() {

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
Serial.begin(115200);
// Serial.setDebugOutput(true);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
Serial.println();
Serial.println();
Serial.println();

for (uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}

Expand All @@ -44,19 +42,19 @@ void setup() {
}

void update_started() {
USE_SERIAL.println("CALLBACK: HTTP update process started");
Serial.println("CALLBACK: HTTP update process started");
}

void update_finished() {
USE_SERIAL.println("CALLBACK: HTTP update process finished");
Serial.println("CALLBACK: HTTP update process finished");
}

void update_progress(int cur, int total) {
USE_SERIAL.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
}

void update_error(int err) {
USE_SERIAL.printf("CALLBACK: HTTP update fatal error code %d\n", err);
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
}


Expand Down Expand Up @@ -86,15 +84,15 @@ void loop() {

switch (ret) {
case HTTP_UPDATE_FAILED:
USE_SERIAL.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
break;

case HTTP_UPDATE_NO_UPDATES:
USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;

case HTTP_UPDATE_OK:
USE_SERIAL.println("HTTP_UPDATE_OK");
Serial.println("HTTP_UPDATE_OK");
break;
}
}
Expand Down
Loading