Skip to content

Commit 2e5ee76

Browse files
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 esp8266#7095
1 parent 4e3a4b6 commit 2e5ee76

File tree

26 files changed

+116
-257
lines changed

26 files changed

+116
-257
lines changed

cores/esp8266/FS.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ using fs::SPIFFSConfig;
266266
#endif //FS_NO_GLOBALS
267267

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

272272
#endif //FS_H

cores/esp8266/spiffs_api.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
3737
return flash_hal_read(addr, size, dst);
3838
}
3939

40-
41-
40+
#pragma GCC diagnostic push
41+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
4242

4343
namespace spiffs_impl {
4444

@@ -149,6 +149,8 @@ extern "C" void spiffs_request_end(void)
149149
SPIFFS.end();
150150
}
151151

152+
#pragma GCC diagnostic pop
153+
152154
#endif // ARDUINO
153155
#endif // !CORE_MOCK
154156

cores/esp8266/spiffs_api.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class SPIFFSImpl : public FSImpl
171171
return false;
172172
}
173173
_cfg = *static_cast<const SPIFFSConfig *>(&cfg);
174-
return true;
174+
return true;
175175
}
176176

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

358358
SPIFFSConfig _cfg;
359+
360+
int _called = 0;
359361
};
360362

361363
#define CHECKFD() while (_fd == 0) { panic(); }

libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unsigned int status = WL_IDLE_STATUS;
5656

5757
void setup() {
5858
delay(1000);
59-
Serial.begin(9600);
59+
Serial.begin(115200);
6060
Serial.println();
6161
Serial.println("Configuring access point...");
6262
/* You can remove the password parameter if you want the AP to be open. */

libraries/EEPROM/examples/eeprom_read/eeprom_read.ino

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ byte value;
1515
void setup() {
1616
// initialize serial and wait for port to open:
1717
Serial.begin(115200);
18-
while (!Serial) {
19-
; // wait for serial port to connect. Needed for Leonardo only
20-
}
2118
EEPROM.begin(512);
2219
}
2320

libraries/ESP8266HTTPClient/examples/PostHttpClient/PostHttpClient.ino

+15-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <ESP8266WiFi.h>
99
#include <ESP8266HTTPClient.h>
1010

11-
#define USE_SERIAL Serial
12-
1311
/* this can be run with an emulated server on host:
1412
cd esp8266-core-root-dir
1513
cd tests/host
@@ -27,21 +25,21 @@
2725

2826
void setup() {
2927

30-
USE_SERIAL.begin(115200);
28+
Serial.begin(115200);
3129

32-
USE_SERIAL.println();
33-
USE_SERIAL.println();
34-
USE_SERIAL.println();
30+
Serial.println();
31+
Serial.println();
32+
Serial.println();
3533

3634
WiFi.begin(STASSID, STAPSK);
3735

3836
while (WiFi.status() != WL_CONNECTED) {
3937
delay(500);
40-
USE_SERIAL.print(".");
38+
Serial.print(".");
4139
}
42-
USE_SERIAL.println("");
43-
USE_SERIAL.print("Connected! IP address: ");
44-
USE_SERIAL.println(WiFi.localIP());
40+
Serial.println("");
41+
Serial.print("Connected! IP address: ");
42+
Serial.println(WiFi.localIP());
4543

4644
}
4745

@@ -52,29 +50,29 @@ void loop() {
5250
WiFiClient client;
5351
HTTPClient http;
5452

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

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

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

6967
// file found at server
7068
if (httpCode == HTTP_CODE_OK) {
7169
const String& payload = http.getString();
72-
USE_SERIAL.println("received payload:\n<<");
73-
USE_SERIAL.println(payload);
74-
USE_SERIAL.println(">>");
70+
Serial.println("received payload:\n<<");
71+
Serial.println(payload);
72+
Serial.println(">>");
7573
}
7674
} else {
77-
USE_SERIAL.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
75+
Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
7876
}
7977

8078
http.end();

libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

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

28-
#define USE_SPIFFS
29-
//#define USE_LITTLEFS
28+
//#define USE_SPIFFS
29+
#define USE_LITTLEFS
3030
//#define USE_SDFS
3131

3232
// Uncomment the following line to embed a version of the web page in the code

libraries/ESP8266WebServer/examples/HttpHashCredAuth/HttpHashCredAuth.ino

+13-12
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
1. Creating a secure web server using ESP8266ESP8266WebServerSecure
88
2. Use of HTTP authentication on this secure server
99
3. A simple web interface to allow an authenticated user to change Credentials
10-
4. Persisting those credentials through a reboot of the ESP by saving them to SPIFFS without storing them as plain text
10+
4. Persisting those credentials through a reboot of the ESP by saving them to LittleFS without storing them as plain text
1111
*/
1212

1313
#include <FS.h>
14+
#include <LittleFS.h>
1415
#include <ESP8266WiFi.h>
1516
#include <ESP8266WebServerSecure.h>
1617

@@ -23,8 +24,8 @@
2324
const char* ssid = STASSID;
2425
const char* wifi_pw = STAPSK;
2526

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

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

8485
ESP8266WebServerSecure server(443);
8586

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

95-
//Initialize SPIFFS to save credentials
96-
if(!SPIFFS.begin()){
97-
Serial.println("SPIFFS initialization error, programmer flash configured?");
96+
//Initialize LittleFS to save credentials
97+
if(!LittleFS.begin()){
98+
Serial.println("LittleFS initialization error, programmer flash configured?");
9899
ESP.restart();
99100
}
100101

@@ -187,16 +188,16 @@ void showcredentialpage(){
187188
server.send(200, "text/html", page);
188189
}
189190

190-
//Saves credentials to SPIFFS
191+
//Saves credentials to LittleFS
191192
void savecredentials(String new_login, String new_password)
192193
{
193194
//Set global variables to new values
194195
login=new_login;
195196
H1=ESP8266WebServer::credentialHash(new_login,realm,new_password);
196197

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

211-
//loads credentials from SPIFFS
212+
//loads credentials from LittleFS
212213
void loadcredentials()
213214
{
214215
Serial.println("Searching for credentials.");
215216
File f;
216-
f=SPIFFS.open(file_credentials,"r");
217+
f=LittleFS.open(file_credentials,"r");
217218
if(f){
218219
Serial.println("Loading credentials from file system.");
219220
String mod=f.readString(); //read the file to a String

libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//
33
// Before running, you must download the set of certs using
44
// the script "certs-from-mozilla.py" (no parameters)
5-
// and then uploading the generated .AR file to SPIFFS or SD.
5+
// and then uploading the generated .AR file to LittleFS or SD.
66
//
77
// You do not need to generate the ".IDX" file listed below,
88
// it is generated automatically when the CertStore object
9-
// is created and written to SD or SPIFFS by the ESP8266.
9+
// is created and written to SD or LittleFS by the ESP8266.
1010
//
1111
// Why would you need a CertStore?
1212
//
@@ -37,6 +37,7 @@
3737
#include <CertStoreBearSSL.h>
3838
#include <time.h>
3939
#include <FS.h>
40+
#include <LittleFS.h>
4041

4142
#ifndef STASSID
4243
#define STASSID "your-ssid"
@@ -117,7 +118,7 @@ void setup() {
117118
Serial.println();
118119
Serial.println();
119120

120-
SPIFFS.begin();
121+
LittleFS.begin();
121122
// If using a SD card or LittleFS, call the appropriate ::begin instead
122123

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

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

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

libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This script pulls the list of Mozilla trusted certificate authorities
44
# from the web at the "mozurl" below, parses the file to grab the PEM
55
# for each cert, and then generates DER files in a new ./data directory
6-
# Upload these to a SPIFFS filesystem and use the CertManager to parse
6+
# Upload these to an on-chip filesystem and use the CertManager to parse
77
# and use them for your outgoing SSL connections.
88
#
99
# Script by Earle F. Philhower, III. Released to the public domain.

libraries/ESP8266WiFi/keywords.txt

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ BearSSL KEYWORD1
2323
X509List KEYWORD1
2424
PrivateKey KEYWORD1
2525
PublicKey KEYWORD1
26-
CertStoreSPIFFSBearSSL KEYWORD1
27-
CertStoreSDBearSSL KEYWORD1
2826
Session KEYWORD1
2927
ESP8266WiFiGratuitous KEYWORD1
3028

libraries/ESP8266WiFi/src/CertStoreBearSSL.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <FS.h>
2727

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

3232
namespace BearSSL {

libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino

+14-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <ESP8266HTTPClient.h>
1414
#include <ESP8266httpUpdate.h>
1515

16-
#define USE_SERIAL Serial
17-
1816
#ifndef APSSID
1917
#define APSSID "APSSID"
2018
#define APPSK "APPSK"
@@ -24,16 +22,16 @@ ESP8266WiFiMulti WiFiMulti;
2422

2523
void setup() {
2624

27-
USE_SERIAL.begin(115200);
28-
// USE_SERIAL.setDebugOutput(true);
25+
Serial.begin(115200);
26+
// Serial.setDebugOutput(true);
2927

30-
USE_SERIAL.println();
31-
USE_SERIAL.println();
32-
USE_SERIAL.println();
28+
Serial.println();
29+
Serial.println();
30+
Serial.println();
3331

3432
for (uint8_t t = 4; t > 0; t--) {
35-
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
36-
USE_SERIAL.flush();
33+
Serial.printf("[SETUP] WAIT %d...\n", t);
34+
Serial.flush();
3735
delay(1000);
3836
}
3937

@@ -44,19 +42,19 @@ void setup() {
4442
}
4543

4644
void update_started() {
47-
USE_SERIAL.println("CALLBACK: HTTP update process started");
45+
Serial.println("CALLBACK: HTTP update process started");
4846
}
4947

5048
void update_finished() {
51-
USE_SERIAL.println("CALLBACK: HTTP update process finished");
49+
Serial.println("CALLBACK: HTTP update process finished");
5250
}
5351

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

5856
void update_error(int err) {
59-
USE_SERIAL.printf("CALLBACK: HTTP update fatal error code %d\n", err);
57+
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
6058
}
6159

6260

@@ -86,15 +84,15 @@ void loop() {
8684

8785
switch (ret) {
8886
case HTTP_UPDATE_FAILED:
89-
USE_SERIAL.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
87+
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
9088
break;
9189

9290
case HTTP_UPDATE_NO_UPDATES:
93-
USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
91+
Serial.println("HTTP_UPDATE_NO_UPDATES");
9492
break;
9593

9694
case HTTP_UPDATE_OK:
97-
USE_SERIAL.println("HTTP_UPDATE_OK");
95+
Serial.println("HTTP_UPDATE_OK");
9896
break;
9997
}
10098
}

0 commit comments

Comments
 (0)