7
7
1. Creating a secure web server using ESP8266ESP8266WebServerSecure
8
8
2. Use of HTTP authentication on this secure server
9
9
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
11
11
*/
12
12
13
13
#include < FS.h>
14
+ #include < LittleFS.h>
14
15
#include < ESP8266WiFi.h>
15
16
#include < ESP8266WebServerSecure.h>
16
17
23
24
const char * ssid = STASSID;
24
25
const char * wifi_pw = STAPSK;
25
26
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
28
29
29
30
// The ESP8266WebServerSecure requires an encryption certificate and matching key.
30
31
// These can generated with the bash script available in the ESP8266 Arduino repository.
@@ -83,7 +84,7 @@ gz5JWYhbD6c38khSzJb0pNXCo3EuYAVa36kDM96k1BtWuhRS10Q1VXk=
83
84
84
85
ESP8266WebServerSecure server (443 );
85
86
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 .
87
88
String login = " admin" ;
88
89
const String realm = " global" ;
89
90
String H1 = " " ;
@@ -92,9 +93,9 @@ String authentication_failed = "User authentication has failed.";
92
93
void setup () {
93
94
Serial.begin (115200 );
94
95
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?" );
98
99
ESP.restart ();
99
100
}
100
101
@@ -187,16 +188,16 @@ void showcredentialpage(){
187
188
server.send (200 , " text/html" , page);
188
189
}
189
190
190
- // Saves credentials to SPIFFS
191
+ // Saves credentials to LittleFS
191
192
void savecredentials (String new_login, String new_password)
192
193
{
193
194
// Set global variables to new values
194
195
login=new_login;
195
196
H1=ESP8266WebServer::credentialHash (new_login,realm,new_password);
196
197
197
- // Save new values to SPIFFS for loading on next reboot
198
+ // Save new values to LittleFS for loading on next reboot
198
199
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
200
201
if (f){
201
202
Serial.println (" Modifying credentials in file system." );
202
203
f.println (login);
@@ -208,12 +209,12 @@ void savecredentials(String new_login, String new_password)
208
209
Serial.println (" Credentials saved." );
209
210
}
210
211
211
- // loads credentials from SPIFFS
212
+ // loads credentials from LittleFS
212
213
void loadcredentials ()
213
214
{
214
215
Serial.println (" Searching for credentials." );
215
216
File f;
216
- f=SPIFFS .open (file_credentials," r" );
217
+ f=LittleFS .open (file_credentials," r" );
217
218
if (f){
218
219
Serial.println (" Loading credentials from file system." );
219
220
String mod=f.readString (); // read the file to a String
0 commit comments