mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Deprecate SPIFFS, move examples to LittleFS (#7263)
* 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 * Remove leftover debug code * Clean up comments in some examples * Update documentation on SPIFFS deprecation * Fix host tests to avoid deprecation warnings * Fix cut-n-paste error * Restore SpeedTest.ino, adjust to allow custom FSes Co-authored-by: Develo <deveyes@gmail.com>
This commit is contained in:
parent
9845deb283
commit
83166f948b
@ -4960,7 +4960,7 @@ espinotee.menu.baud.3000000.upload.speed=3000000
|
|||||||
wifinfo.name=WifInfo
|
wifinfo.name=WifInfo
|
||||||
wifinfo.build.board=WIFINFO
|
wifinfo.build.board=WIFINFO
|
||||||
wifinfo.build.variant=wifinfo
|
wifinfo.build.variant=wifinfo
|
||||||
wifinfo.menu.ESPModule.ESP07192=ESP07 (1M/192K SPIFFS)
|
wifinfo.menu.ESPModule.ESP07192=ESP07 (1M/192K FS)
|
||||||
wifinfo.menu.ESPModule.ESP07192.build.board=ESP8266_ESP07
|
wifinfo.menu.ESPModule.ESP07192.build.board=ESP8266_ESP07
|
||||||
wifinfo.menu.ESPModule.ESP07192.build.flash_ld=eagle.flash.1m192.ld
|
wifinfo.menu.ESPModule.ESP07192.build.flash_ld=eagle.flash.1m192.ld
|
||||||
wifinfo.menu.ESPModule.ESP07192.build.flash_size=1M
|
wifinfo.menu.ESPModule.ESP07192.build.flash_size=1M
|
||||||
@ -4968,7 +4968,7 @@ wifinfo.menu.ESPModule.ESP07192.build.spiffs_blocksize=4096
|
|||||||
wifinfo.menu.ESPModule.ESP07192.build.spiffs_end=0xFB000
|
wifinfo.menu.ESPModule.ESP07192.build.spiffs_end=0xFB000
|
||||||
wifinfo.menu.ESPModule.ESP07192.build.spiffs_start=0xCB000
|
wifinfo.menu.ESPModule.ESP07192.build.spiffs_start=0xCB000
|
||||||
wifinfo.menu.ESPModule.ESP07192.upload.maximum_size=827376
|
wifinfo.menu.ESPModule.ESP07192.upload.maximum_size=827376
|
||||||
wifinfo.menu.ESPModule.ESP12=ESP12 (4M/1M SPIFFS)
|
wifinfo.menu.ESPModule.ESP12=ESP12 (4M/1M FS)
|
||||||
wifinfo.menu.ESPModule.ESP12.build.board=ESP8266_ESP12
|
wifinfo.menu.ESPModule.ESP12.build.board=ESP8266_ESP12
|
||||||
wifinfo.menu.ESPModule.ESP12.build.flash_ld=eagle.flash.4m1m.ld
|
wifinfo.menu.ESPModule.ESP12.build.flash_ld=eagle.flash.4m1m.ld
|
||||||
wifinfo.menu.ESPModule.ESP12.build.flash_size=4M
|
wifinfo.menu.ESPModule.ESP12.build.flash_size=4M
|
||||||
|
@ -266,7 +266,7 @@ using fs::SPIFFSConfig;
|
|||||||
#endif //FS_NO_GLOBALS
|
#endif //FS_NO_GLOBALS
|
||||||
|
|
||||||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPIFFS)
|
#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
|
||||||
|
|
||||||
#endif //FS_H
|
#endif //FS_H
|
||||||
|
@ -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);
|
return flash_hal_read(addr, size, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
namespace spiffs_impl {
|
namespace spiffs_impl {
|
||||||
|
|
||||||
@ -149,6 +149,8 @@ extern "C" void spiffs_request_end(void)
|
|||||||
SPIFFS.end();
|
SPIFFS.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
#endif // ARDUINO
|
#endif // ARDUINO
|
||||||
#endif // !CORE_MOCK
|
#endif // !CORE_MOCK
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_cfg = *static_cast<const SPIFFSConfig *>(&cfg);
|
_cfg = *static_cast<const SPIFFSConfig *>(&cfg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool begin() override
|
bool begin() override
|
||||||
|
@ -344,7 +344,7 @@ Parameters in Arduino IDE:
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
- Card: "WEMOS D1 Mini Lite"
|
- Card: "WEMOS D1 Mini Lite"
|
||||||
- Flash Size: "1M (512K SPIFFS)"
|
- Flash Size: "1M (512K FS)"
|
||||||
- CPU Frequency: "80 Mhz"
|
- CPU Frequency: "80 Mhz"
|
||||||
|
|
||||||
Power:
|
Power:
|
||||||
|
@ -102,9 +102,9 @@ The web browser you're using to read this document keeps a list of 100s of certi
|
|||||||
|
|
||||||
In many cases your application will know the specific CA it needs to validate web or MQTT servers against (often just a single, self-signing CA private to your institution). Simply load your private CA in a `BearSSL::X509List` and use that as your trust anchor.
|
In many cases your application will know the specific CA it needs to validate web or MQTT servers against (often just a single, self-signing CA private to your institution). Simply load your private CA in a `BearSSL::X509List` and use that as your trust anchor.
|
||||||
|
|
||||||
However, there are cases where you will not know beforehand which CA you will need (i.e. a user enters a website through a keypad), and you need to keep the list of CAs just like your web browser. In those cases, you need to generate a certificate bundle on the PC while compiling your application, upload the `certs.ar` bundle to SPIFFS or SD when uploading your application binary, and pass it to a `BearSSL::CertStore()` in order to validate TLS peers.
|
However, there are cases where you will not know beforehand which CA you will need (i.e. a user enters a website through a keypad), and you need to keep the list of CAs just like your web browser. In those cases, you need to generate a certificate bundle on the PC while compiling your application, upload the `certs.ar` bundle to LittleFS or SD when uploading your application binary, and pass it to a `BearSSL::CertStore()` in order to validate TLS peers.
|
||||||
|
|
||||||
See the `BearSSL_CertStore` example for full details as the `BearSSL::CertStore` requires the creation of a cookie-cutter object for filesystem access (because the SD and SPIFFS filesystems are presently incompatible with each other). At a high level in your `setup()` you will call `BearSSL::initCertStore()` on a global object, and then pass this global certificate store to `client.setCertStore(&gCA)` before every connection attempt to enable it as a validation option.
|
See the `BearSSL_CertStore` example for full details.
|
||||||
|
|
||||||
Supported Crypto
|
Supported Crypto
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
@ -42,23 +42,24 @@ Load client certificate from file system.
|
|||||||
.. code:: cpp
|
.. code:: cpp
|
||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClientSecure.h>
|
#include <WiFiClientSecure.h>
|
||||||
|
|
||||||
const char* certyficateFile = "/client.cer";
|
const char* certificateFile = "/client.cer";
|
||||||
|
|
||||||
*setup() or loop()*
|
*setup() or loop()*
|
||||||
|
|
||||||
.. code:: cpp
|
.. code:: cpp
|
||||||
|
|
||||||
if (!SPIFFS.begin())
|
if (!LittleFS.begin())
|
||||||
{
|
{
|
||||||
Serial.println("Failed to mount the file system");
|
Serial.println("Failed to mount the file system");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("Opening %s", certyficateFile);
|
Serial.printf("Opening %s", certificateFile);
|
||||||
File crtFile = SPIFFS.open(certyficateFile, "r");
|
File crtFile = LittleFS.open(certificateFile, "r");
|
||||||
if (!crtFile)
|
if (!crtFile)
|
||||||
{
|
{
|
||||||
Serial.println(" Failed!");
|
Serial.println(" Failed!");
|
||||||
@ -66,7 +67,7 @@ Load client certificate from file system.
|
|||||||
|
|
||||||
WiFiClientSecure client;
|
WiFiClientSecure client;
|
||||||
|
|
||||||
Serial.print("Loading %s", certyficateFile);
|
Serial.print("Loading %s", certificateFile);
|
||||||
if (!client.loadCertificate(crtFile))
|
if (!client.loadCertificate(crtFile))
|
||||||
{
|
{
|
||||||
Serial.println(" Failed!");
|
Serial.println(" Failed!");
|
||||||
|
@ -79,7 +79,7 @@ perform. It is not listed among libraries verified to work with ESP8266.
|
|||||||
|
|
||||||
`Read more <a03-library-does-not-work.rst>`__.
|
`Read more <a03-library-does-not-work.rst>`__.
|
||||||
|
|
||||||
In the IDE, for ESP-12E that has 4M flash, I can choose 4M (1M SPIFFS) or 4M (3M SPIFFS). No matter what I select, the IDE tells me the maximum code space is about 1M. Where does my flash go?
|
In the IDE, for ESP-12E that has 4M flash, I can choose 4M (1M FS) or 4M (3M FS). No matter what I select, the IDE tells me the maximum code space is about 1M. Where does my flash go?
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The reason we cannot have more than 1MB of code in flash has to do with
|
The reason we cannot have more than 1MB of code in flash has to do with
|
||||||
@ -90,7 +90,7 @@ total, but switching such "banks" on the fly is not easy and efficient,
|
|||||||
so we don't bother doing that. Besides, no one has so far complained
|
so we don't bother doing that. Besides, no one has so far complained
|
||||||
about 1MB of code space being insufficient for practical purposes.
|
about 1MB of code space being insufficient for practical purposes.
|
||||||
|
|
||||||
The option to choose 3M or 1M SPIFFS is to optimize the upload time.
|
The option to choose 3M or 1M filesystem is to optimize the upload time.
|
||||||
Uploading 3MB takes a long time so sometimes you can just use 1MB. Other
|
Uploading 3MB takes a long time so sometimes you can just use 1MB. Other
|
||||||
2MB of flash can still be used with ``ESP.flashRead`` and
|
2MB of flash can still be used with ``ESP.flashRead`` and
|
||||||
``ESP.flashWrite`` APIs if necessary.
|
``ESP.flashWrite`` APIs if necessary.
|
||||||
|
@ -63,6 +63,16 @@ following include to the sketch:
|
|||||||
|
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
|
|
||||||
|
SPIFFS Deprecation Warning
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
SPIFFS is currently deprecated and may be removed in future releases of
|
||||||
|
the core. Please consider moving your code to LittleFS. SPIFFS is not
|
||||||
|
actively supported anymore by the upstream developer, while LittleFS is
|
||||||
|
under active development, supports real directories, and is many times
|
||||||
|
faster for most operations.
|
||||||
|
|
||||||
|
|
||||||
SPIFFS and LittleFS
|
SPIFFS and LittleFS
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
@ -244,6 +244,6 @@ BeagleBone, CubieBoard).
|
|||||||
- `What is PlatformIO? <https://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=arduino-esp8266>`__
|
- `What is PlatformIO? <https://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=arduino-esp8266>`__
|
||||||
- `PlatformIO IDE <https://platformio.org/platformio-ide?utm_source=arduino-esp8266>`__
|
- `PlatformIO IDE <https://platformio.org/platformio-ide?utm_source=arduino-esp8266>`__
|
||||||
- `PlatformIO Core <https://docs.platformio.org/en/latest/core.html?utm_source=arduino-esp8266>`__ (command line tool)
|
- `PlatformIO Core <https://docs.platformio.org/en/latest/core.html?utm_source=arduino-esp8266>`__ (command line tool)
|
||||||
- `Advanced usage <https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266>`__ - custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version
|
- `Advanced usage <https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266>`__ - custom settings, uploading to LittleFS, Over-the-Air (OTA), staging version
|
||||||
- `Integration with Cloud and Standalone IDEs <https://docs.platformio.org/en/latest/ide.html?utm_source=arduino-esp8266>`__ - Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode
|
- `Integration with Cloud and Standalone IDEs <https://docs.platformio.org/en/latest/ide.html?utm_source=arduino-esp8266>`__ - Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode
|
||||||
- `Project Examples <https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266#examples>`__
|
- `Project Examples <https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266#examples>`__
|
||||||
|
@ -25,7 +25,7 @@ This is a bit different from standard EEPROM class. You need to call ``EEPROM.be
|
|||||||
|
|
||||||
``EEPROM.write`` does not write to flash immediately, instead you must call ``EEPROM.commit()`` whenever you wish to save changes to flash. ``EEPROM.end()`` will also commit, and will release the RAM copy of EEPROM contents.
|
``EEPROM.write`` does not write to flash immediately, instead you must call ``EEPROM.commit()`` whenever you wish to save changes to flash. ``EEPROM.end()`` will also commit, and will release the RAM copy of EEPROM contents.
|
||||||
|
|
||||||
EEPROM library uses one sector of flash located just after the SPIFFS.
|
EEPROM library uses one sector of flash located just after the embedded filesystem.
|
||||||
|
|
||||||
`Three examples <https://github.com/esp8266/Arduino/tree/master/libraries/EEPROM>`__ included.
|
`Three examples <https://github.com/esp8266/Arduino/tree/master/libraries/EEPROM>`__ included.
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ If this is the case, then most likely ESP module has not been reset after initia
|
|||||||
The most common causes of OTA failure are as follows:
|
The most common causes of OTA failure are as follows:
|
||||||
|
|
||||||
- not enough physical memory on the chip (e.g. ESP01 with 512K flash memory is not enough for OTA).
|
- not enough physical memory on the chip (e.g. ESP01 with 512K flash memory is not enough for OTA).
|
||||||
- too much memory declared for SPIFFS so new sketch will not fit between existing sketch and SPIFFS – see `Update process - memory view <#update-process-memory-view>`__.
|
- too much memory declared for the filesystem so new sketch will not fit between existing sketch and the filesystem – see `Update process - memory view <#update-process-memory-view>`__.
|
||||||
- too little memory declared in Arduino IDE for your selected board (i.e. less than physical size).
|
- too little memory declared in Arduino IDE for your selected board (i.e. less than physical size).
|
||||||
- not resetting the ESP module after initial upload using serial port.
|
- not resetting the ESP module after initial upload using serial port.
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ unsigned int status = WL_IDLE_STATUS;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("Configuring access point...");
|
Serial.println("Configuring access point...");
|
||||||
/* You can remove the password parameter if you want the AP to be open. */
|
/* You can remove the password parameter if you want the AP to be open. */
|
||||||
|
@ -15,9 +15,6 @@ byte value;
|
|||||||
void setup() {
|
void setup() {
|
||||||
// initialize serial and wait for port to open:
|
// initialize serial and wait for port to open:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial) {
|
|
||||||
; // wait for serial port to connect. Needed for Leonardo only
|
|
||||||
}
|
|
||||||
EEPROM.begin(512);
|
EEPROM.begin(512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
|
||||||
|
|
||||||
/* this can be run with an emulated server on host:
|
/* this can be run with an emulated server on host:
|
||||||
cd esp8266-core-root-dir
|
cd esp8266-core-root-dir
|
||||||
cd tests/host
|
cd tests/host
|
||||||
@ -27,21 +25,21 @@
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
USE_SERIAL.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
|
|
||||||
WiFi.begin(STASSID, STAPSK);
|
WiFi.begin(STASSID, STAPSK);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
USE_SERIAL.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
USE_SERIAL.println("");
|
Serial.println("");
|
||||||
USE_SERIAL.print("Connected! IP address: ");
|
Serial.print("Connected! IP address: ");
|
||||||
USE_SERIAL.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,29 +50,29 @@ void loop() {
|
|||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
USE_SERIAL.print("[HTTP] begin...\n");
|
Serial.print("[HTTP] begin...\n");
|
||||||
// configure traged server and url
|
// configure traged server and url
|
||||||
http.begin(client, "http://" SERVER_IP "/postplain/"); //HTTP
|
http.begin(client, "http://" SERVER_IP "/postplain/"); //HTTP
|
||||||
http.addHeader("Content-Type", "application/json");
|
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
|
// start connection and send HTTP header and body
|
||||||
int httpCode = http.POST("{\"hello\":\"world\"}");
|
int httpCode = http.POST("{\"hello\":\"world\"}");
|
||||||
|
|
||||||
// httpCode will be negative on error
|
// httpCode will be negative on error
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
// HTTP header has been send and Server response header has been handled
|
// 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
|
// file found at server
|
||||||
if (httpCode == HTTP_CODE_OK) {
|
if (httpCode == HTTP_CODE_OK) {
|
||||||
const String& payload = http.getString();
|
const String& payload = http.getString();
|
||||||
USE_SERIAL.println("received payload:\n<<");
|
Serial.println("received payload:\n<<");
|
||||||
USE_SERIAL.println(payload);
|
Serial.println(payload);
|
||||||
USE_SERIAL.println(">>");
|
Serial.println(">>");
|
||||||
}
|
}
|
||||||
} else {
|
} 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();
|
http.end();
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
// Select the FileSystem by uncommenting one of the lines below
|
// Select the FileSystem by uncommenting one of the lines below
|
||||||
|
|
||||||
#define USE_SPIFFS
|
//#define USE_SPIFFS
|
||||||
//#define USE_LITTLEFS
|
#define USE_LITTLEFS
|
||||||
//#define USE_SDFS
|
//#define USE_SDFS
|
||||||
|
|
||||||
// Uncomment the following line to embed a version of the web page in the code
|
// Uncomment the following line to embed a version of the web page in the code
|
||||||
|
@ -7,10 +7,11 @@
|
|||||||
1. Creating a secure web server using ESP8266ESP8266WebServerSecure
|
1. Creating a secure web server using ESP8266ESP8266WebServerSecure
|
||||||
2. Use of HTTP authentication on this secure server
|
2. Use of HTTP authentication on this secure server
|
||||||
3. A simple web interface to allow an authenticated user to change Credentials
|
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 <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServerSecure.h>
|
#include <ESP8266WebServerSecure.h>
|
||||||
|
|
||||||
@ -23,8 +24,8 @@
|
|||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
const char* wifi_pw = STAPSK;
|
const char* wifi_pw = STAPSK;
|
||||||
|
|
||||||
const String file_credentials = R"(/credentials.txt)"; //SPIFFS file name for the saved credentials
|
const String file_credentials = R"(/credentials.txt)"; // LittleFS file name for the saved credentials
|
||||||
const String change_creds = "changecreds"; //address for a credential change
|
const String change_creds = "changecreds"; // Address for a credential change
|
||||||
|
|
||||||
//The ESP8266WebServerSecure requires an encryption certificate and matching key.
|
//The ESP8266WebServerSecure requires an encryption certificate and matching key.
|
||||||
//These can generated with the bash script available in the ESP8266 Arduino repository.
|
//These can generated with the bash script available in the ESP8266 Arduino repository.
|
||||||
@ -83,7 +84,7 @@ gz5JWYhbD6c38khSzJb0pNXCo3EuYAVa36kDM96k1BtWuhRS10Q1VXk=
|
|||||||
|
|
||||||
ESP8266WebServerSecure server(443);
|
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";
|
String login = "admin";
|
||||||
const String realm = "global";
|
const String realm = "global";
|
||||||
String H1 = "";
|
String H1 = "";
|
||||||
@ -92,9 +93,9 @@ String authentication_failed = "User authentication has failed.";
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
//Initialize SPIFFS to save credentials
|
//Initialize LittleFS to save credentials
|
||||||
if(!SPIFFS.begin()){
|
if(!LittleFS.begin()){
|
||||||
Serial.println("SPIFFS initialization error, programmer flash configured?");
|
Serial.println("LittleFS initialization error, programmer flash configured?");
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,16 +188,16 @@ void showcredentialpage(){
|
|||||||
server.send(200, "text/html", page);
|
server.send(200, "text/html", page);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Saves credentials to SPIFFS
|
//Saves credentials to LittleFS
|
||||||
void savecredentials(String new_login, String new_password)
|
void savecredentials(String new_login, String new_password)
|
||||||
{
|
{
|
||||||
//Set global variables to new values
|
//Set global variables to new values
|
||||||
login=new_login;
|
login=new_login;
|
||||||
H1=ESP8266WebServer::credentialHash(new_login,realm,new_password);
|
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.");
|
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){
|
if(f){
|
||||||
Serial.println("Modifying credentials in file system.");
|
Serial.println("Modifying credentials in file system.");
|
||||||
f.println(login);
|
f.println(login);
|
||||||
@ -208,12 +209,12 @@ void savecredentials(String new_login, String new_password)
|
|||||||
Serial.println("Credentials saved.");
|
Serial.println("Credentials saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//loads credentials from SPIFFS
|
//loads credentials from LittleFS
|
||||||
void loadcredentials()
|
void loadcredentials()
|
||||||
{
|
{
|
||||||
Serial.println("Searching for credentials.");
|
Serial.println("Searching for credentials.");
|
||||||
File f;
|
File f;
|
||||||
f=SPIFFS.open(file_credentials,"r");
|
f=LittleFS.open(file_credentials,"r");
|
||||||
if(f){
|
if(f){
|
||||||
Serial.println("Loading credentials from file system.");
|
Serial.println("Loading credentials from file system.");
|
||||||
String mod=f.readString(); //read the file to a String
|
String mod=f.readString(); //read the file to a String
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
//
|
//
|
||||||
// Before running, you must download the set of certs using
|
// Before running, you must download the set of certs using
|
||||||
// the script "certs-from-mozilla.py" (no parameters)
|
// 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,
|
// You do not need to generate the ".IDX" file listed below,
|
||||||
// it is generated automatically when the CertStore object
|
// 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?
|
// Why would you need a CertStore?
|
||||||
//
|
//
|
||||||
@ -37,6 +37,7 @@
|
|||||||
#include <CertStoreBearSSL.h>
|
#include <CertStoreBearSSL.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
#ifndef STASSID
|
#ifndef STASSID
|
||||||
#define STASSID "your-ssid"
|
#define STASSID "your-ssid"
|
||||||
@ -117,8 +118,7 @@ void setup() {
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
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
|
// We start by connecting to a WiFi network
|
||||||
Serial.print("Connecting to ");
|
Serial.print("Connecting to ");
|
||||||
@ -138,10 +138,10 @@ void setup() {
|
|||||||
|
|
||||||
setClock(); // Required for X.509 validation
|
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);
|
Serial.printf("Number of CA certs read: %d\n", numCerts);
|
||||||
if (numCerts == 0) {
|
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!
|
return; // Can't connect to anything w/o certs!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# This script pulls the list of Mozilla trusted certificate authorities
|
# This script pulls the list of Mozilla trusted certificate authorities
|
||||||
# from the web at the "mozurl" below, parses the file to grab the PEM
|
# 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
|
# 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.
|
# and use them for your outgoing SSL connections.
|
||||||
#
|
#
|
||||||
# Script by Earle F. Philhower, III. Released to the public domain.
|
# Script by Earle F. Philhower, III. Released to the public domain.
|
||||||
|
@ -23,8 +23,6 @@ BearSSL KEYWORD1
|
|||||||
X509List KEYWORD1
|
X509List KEYWORD1
|
||||||
PrivateKey KEYWORD1
|
PrivateKey KEYWORD1
|
||||||
PublicKey KEYWORD1
|
PublicKey KEYWORD1
|
||||||
CertStoreSPIFFSBearSSL KEYWORD1
|
|
||||||
CertStoreSDBearSSL KEYWORD1
|
|
||||||
Session KEYWORD1
|
Session KEYWORD1
|
||||||
ESP8266WiFiGratuitous KEYWORD1
|
ESP8266WiFiGratuitous KEYWORD1
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
|
||||||
// Base class for the certificate stores, which allow use
|
// 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
|
// be dynamically used when validating a X509 certificate
|
||||||
|
|
||||||
namespace BearSSL {
|
namespace BearSSL {
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
#include <ESP8266httpUpdate.h>
|
#include <ESP8266httpUpdate.h>
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
|
||||||
|
|
||||||
#ifndef APSSID
|
#ifndef APSSID
|
||||||
#define APSSID "APSSID"
|
#define APSSID "APSSID"
|
||||||
#define APPSK "APPSK"
|
#define APPSK "APPSK"
|
||||||
@ -24,16 +22,16 @@ ESP8266WiFiMulti WiFiMulti;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
USE_SERIAL.begin(115200);
|
Serial.begin(115200);
|
||||||
// USE_SERIAL.setDebugOutput(true);
|
// Serial.setDebugOutput(true);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
|
|
||||||
for (uint8_t t = 4; t > 0; t--) {
|
for (uint8_t t = 4; t > 0; t--) {
|
||||||
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
Serial.printf("[SETUP] WAIT %d...\n", t);
|
||||||
USE_SERIAL.flush();
|
Serial.flush();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,19 +42,19 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update_started() {
|
void update_started() {
|
||||||
USE_SERIAL.println("CALLBACK: HTTP update process started");
|
Serial.println("CALLBACK: HTTP update process started");
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_finished() {
|
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) {
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -86,15 +84,15 @@ void loop() {
|
|||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case HTTP_UPDATE_FAILED:
|
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;
|
break;
|
||||||
|
|
||||||
case HTTP_UPDATE_NO_UPDATES:
|
case HTTP_UPDATE_NO_UPDATES:
|
||||||
USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
|
Serial.println("HTTP_UPDATE_NO_UPDATES");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_UPDATE_OK:
|
case HTTP_UPDATE_OK:
|
||||||
USE_SERIAL.println("HTTP_UPDATE_OK");
|
Serial.println("HTTP_UPDATE_OK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
httpUpdateSPIFFS.ino
|
httpUpdateLittleFS.ino
|
||||||
|
|
||||||
Created on: 05.12.2015
|
Created on: 05.12.2015
|
||||||
|
|
||||||
@ -13,8 +13,6 @@
|
|||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
#include <ESP8266httpUpdate.h>
|
#include <ESP8266httpUpdate.h>
|
||||||
|
|
||||||
#define USE_SERIAL Serial
|
|
||||||
|
|
||||||
ESP8266WiFiMulti WiFiMulti;
|
ESP8266WiFiMulti WiFiMulti;
|
||||||
|
|
||||||
#ifndef APSSID
|
#ifndef APSSID
|
||||||
@ -24,16 +22,16 @@ ESP8266WiFiMulti WiFiMulti;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
USE_SERIAL.begin(115200);
|
Serial.begin(115200);
|
||||||
// USE_SERIAL.setDebugOutput(true);
|
// Serial.setDebugOutput(true);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
|
|
||||||
for (uint8_t t = 4; t > 0; t--) {
|
for (uint8_t t = 4; t > 0; t--) {
|
||||||
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
Serial.printf("[SETUP] WAIT %d...\n", t);
|
||||||
USE_SERIAL.flush();
|
Serial.flush();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +44,7 @@ void loop() {
|
|||||||
// wait for WiFi connection
|
// wait for WiFi connection
|
||||||
if ((WiFiMulti.run() == WL_CONNECTED)) {
|
if ((WiFiMulti.run() == WL_CONNECTED)) {
|
||||||
|
|
||||||
USE_SERIAL.println("Update SPIFFS...");
|
Serial.println("Update LittleFS...");
|
||||||
|
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
|
|
||||||
@ -58,22 +56,22 @@ void loop() {
|
|||||||
// value is used to put the LED on. If the LED is on with HIGH, that value should be passed
|
// value is used to put the LED on. If the LED is on with HIGH, that value should be passed
|
||||||
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
|
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
|
||||||
|
|
||||||
t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(client, "http://server/spiffs.bin");
|
t_httpUpdate_return ret = ESPhttpUpdate.updateFS(client, "http://server/spiffs.bin");
|
||||||
if (ret == HTTP_UPDATE_OK) {
|
if (ret == HTTP_UPDATE_OK) {
|
||||||
USE_SERIAL.println("Update sketch...");
|
Serial.println("Update sketch...");
|
||||||
ret = ESPhttpUpdate.update(client, "http://server/file.bin");
|
ret = ESPhttpUpdate.update(client, "http://server/file.bin");
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case HTTP_UPDATE_FAILED:
|
case HTTP_UPDATE_FAILED:
|
||||||
USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
|
Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_UPDATE_NO_UPDATES:
|
case HTTP_UPDATE_NO_UPDATES:
|
||||||
USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
|
Serial.println("HTTP_UPDATE_NO_UPDATES");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_UPDATE_OK:
|
case HTTP_UPDATE_OK:
|
||||||
USE_SERIAL.println("HTTP_UPDATE_OK");
|
Serial.println("HTTP_UPDATE_OK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,8 +14,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
#define USE_SERIAL Serial
|
|
||||||
|
|
||||||
#ifndef APSSID
|
#ifndef APSSID
|
||||||
#define APSSID "APSSID"
|
#define APSSID "APSSID"
|
||||||
@ -34,46 +33,47 @@ BearSSL::CertStore certStore;
|
|||||||
void setClock() {
|
void setClock() {
|
||||||
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC
|
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC
|
||||||
|
|
||||||
USE_SERIAL.print(F("Waiting for NTP time sync: "));
|
Serial.print(F("Waiting for NTP time sync: "));
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
while (now < 8 * 3600 * 2) {
|
while (now < 8 * 3600 * 2) {
|
||||||
yield();
|
yield();
|
||||||
delay(500);
|
delay(500);
|
||||||
USE_SERIAL.print(F("."));
|
Serial.print(F("."));
|
||||||
now = time(nullptr);
|
now = time(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
USE_SERIAL.println(F(""));
|
Serial.println(F(""));
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
gmtime_r(&now, &timeinfo);
|
gmtime_r(&now, &timeinfo);
|
||||||
USE_SERIAL.print(F("Current time: "));
|
Serial.print(F("Current time: "));
|
||||||
USE_SERIAL.print(asctime(&timeinfo));
|
Serial.print(asctime(&timeinfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
USE_SERIAL.begin(115200);
|
Serial.begin(115200);
|
||||||
// USE_SERIAL.setDebugOutput(true);
|
// Serial.setDebugOutput(true);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
USE_SERIAL.println();
|
Serial.println();
|
||||||
|
|
||||||
for (uint8_t t = 4; t > 0; t--) {
|
for (uint8_t t = 4; t > 0; t--) {
|
||||||
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
|
Serial.printf("[SETUP] WAIT %d...\n", t);
|
||||||
USE_SERIAL.flush();
|
Serial.flush();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFiMulti.addAP(APSSID, APPSK);
|
WiFiMulti.addAP(APSSID, APPSK);
|
||||||
|
|
||||||
SPIFFS.begin();
|
LittleFS.begin();
|
||||||
|
|
||||||
int numCerts = certStore.initCertStore(SPIFFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
|
int numCerts = certStore.initCertStore(LittleFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
|
||||||
USE_SERIAL.print(F("Number of CA certs read: ")); USE_SERIAL.println(numCerts);
|
Serial.print(F("Number of CA certs read: "));
|
||||||
|
Serial.println(numCerts);
|
||||||
if (numCerts == 0) {
|
if (numCerts == 0) {
|
||||||
USE_SERIAL.println(F("No certs found. Did you run certs-from-mozill.py and upload the SPIFFS directory before running?"));
|
Serial.println(F("No certs found. Did you run certs-from-mozill.py and upload the LittleFS directory before running?"));
|
||||||
return; // Can't connect to anything w/o certs!
|
return; // Can't connect to anything w/o certs!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ void loop() {
|
|||||||
|
|
||||||
BearSSL::WiFiClientSecure client;
|
BearSSL::WiFiClientSecure client;
|
||||||
bool mfln = client.probeMaxFragmentLength("server", 443, 1024); // server must be the same as in ESPhttpUpdate.update()
|
bool mfln = client.probeMaxFragmentLength("server", 443, 1024); // server must be the same as in ESPhttpUpdate.update()
|
||||||
USE_SERIAL.printf("MFLN supported: %s\n", mfln ? "yes" : "no");
|
Serial.printf("MFLN supported: %s\n", mfln ? "yes" : "no");
|
||||||
if (mfln) {
|
if (mfln) {
|
||||||
client.setBufferSizes(1024, 1024);
|
client.setBufferSizes(1024, 1024);
|
||||||
}
|
}
|
||||||
@ -107,15 +107,15 @@ void loop() {
|
|||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case HTTP_UPDATE_FAILED:
|
case HTTP_UPDATE_FAILED:
|
||||||
USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
|
Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_UPDATE_NO_UPDATES:
|
case HTTP_UPDATE_NO_UPDATES:
|
||||||
USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
|
Serial.println("HTTP_UPDATE_NO_UPDATES");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_UPDATE_OK:
|
case HTTP_UPDATE_OK:
|
||||||
USE_SERIAL.println("HTTP_UPDATE_OK");
|
Serial.println("HTTP_UPDATE_OK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::updateSpiffs(const String& url, const String
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HTTPUpdateResult ESP8266HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion)
|
HTTPUpdateResult ESP8266HTTPUpdate::updateFS(WiFiClient& client, const String& url, const String& currentVersion)
|
||||||
{
|
{
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.begin(client, url);
|
http.begin(client, url);
|
||||||
|
@ -146,7 +146,10 @@ public:
|
|||||||
t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion, const String& httpsFingerprint) __attribute__((deprecated));
|
t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion, const String& httpsFingerprint) __attribute__((deprecated));
|
||||||
t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion, const uint8_t httpsFingerprint[20]) __attribute__((deprecated)); // BearSSL
|
t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion, const uint8_t httpsFingerprint[20]) __attribute__((deprecated)); // BearSSL
|
||||||
#endif
|
#endif
|
||||||
t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = "");
|
t_httpUpdate_return updateFS(WiFiClient& client, const String& url, const String& currentVersion = "");
|
||||||
|
t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = "") __attribute__((deprecated)) {
|
||||||
|
return updateFS(client, url, currentVersion);
|
||||||
|
};
|
||||||
|
|
||||||
// Notification callbacks
|
// Notification callbacks
|
||||||
void onStart(HTTPUpdateStartCB cbOnStart) { _cbStart = cbOnStart; }
|
void onStart(HTTPUpdateStartCB cbOnStart) { _cbStart = cbOnStart; }
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
@file OTA-mDNS-SPIFFS.ino
|
@file OTA-mDNS-LittleFS.ino
|
||||||
|
|
||||||
@author Pascal Gollor (http://www.pgollor.de/cms/)
|
@author Pascal Gollor (http://www.pgollor.de/cms/)
|
||||||
@date 2015-09-18
|
@date 2015-09-18
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ const char* ap_default_psk = STAPSK; ///< Default PSK.
|
|||||||
*/
|
*/
|
||||||
bool loadConfig(String *ssid, String *pass) {
|
bool loadConfig(String *ssid, String *pass) {
|
||||||
// open file for reading.
|
// open file for reading.
|
||||||
File configFile = SPIFFS.open("/cl_conf.txt", "r");
|
File configFile = LittleFS.open("/cl_conf.txt", "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
Serial.println("Failed to open cl_conf.txt.");
|
Serial.println("Failed to open cl_conf.txt.");
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ bool loadConfig(String *ssid, String *pass) {
|
|||||||
*/
|
*/
|
||||||
bool saveConfig(String *ssid, String *pass) {
|
bool saveConfig(String *ssid, String *pass) {
|
||||||
// Open config file for writing.
|
// Open config file for writing.
|
||||||
File configFile = SPIFFS.open("/cl_conf.txt", "w");
|
File configFile = LittleFS.open("/cl_conf.txt", "w");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
Serial.println("Failed to open cl_conf.txt for writing");
|
Serial.println("Failed to open cl_conf.txt for writing");
|
||||||
|
|
||||||
@ -158,7 +159,7 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
// Initialize file system.
|
// Initialize file system.
|
||||||
if (!SPIFFS.begin()) {
|
if (!LittleFS.begin()) {
|
||||||
Serial.println("Failed to mount file system");
|
Serial.println("Failed to mount file system");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -1,8 +1,17 @@
|
|||||||
// Simple speed test for filesystem objects
|
// Simple speed test for filesystem objects
|
||||||
// Released to the public domain by Earle F. Philhower, III
|
// Released to the public domain by Earle F. Philhower, III
|
||||||
|
|
||||||
|
#include <FS.h>
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
// Choose the filesystem to test
|
||||||
|
// WARNING: The filesystem will be formatted at the start of the test!
|
||||||
|
|
||||||
|
#define TESTFS LittleFS
|
||||||
|
//#define TESTFS SPIFFS
|
||||||
|
//#define TESTFS SDFS
|
||||||
|
|
||||||
|
// How large of a file to test
|
||||||
#define TESTSIZEKB 512
|
#define TESTSIZEKB 512
|
||||||
|
|
||||||
void DoTest(FS *fs) {
|
void DoTest(FS *fs) {
|
||||||
@ -112,12 +121,9 @@ void DoTest(FS *fs) {
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.printf("Beginning LittleFS test\n");
|
Serial.printf("Beginning test\n");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
DoTest(&LittleFS);
|
DoTest(&TESTFS);
|
||||||
Serial.printf("Beginning SPIFFS test\n");
|
|
||||||
Serial.flush();
|
|
||||||
DoTest(&SPIFFS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
@ -27,11 +27,7 @@ const int chipSelect = 4;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Open serial communications and wait for port to open:
|
// Open serial communications and wait for port to open:
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial) {
|
|
||||||
; // wait for serial port to connect. Needed for Leonardo only
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
|
@ -27,11 +27,7 @@ const int chipSelect = 4;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Open serial communications and wait for port to open:
|
// Open serial communications and wait for port to open:
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial) {
|
|
||||||
; // wait for serial port to connect. Needed for Leonardo only
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
|
@ -24,11 +24,7 @@ File myFile;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Open serial communications and wait for port to open:
|
// Open serial communications and wait for port to open:
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial) {
|
|
||||||
; // wait for serial port to connect. Needed for Leonardo only
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
|
@ -25,11 +25,7 @@ File myFile;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Open serial communications and wait for port to open:
|
// Open serial communications and wait for port to open:
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
while (!Serial) {
|
|
||||||
; // wait for serial port to connect. Needed for Leonardo only
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ File bmpFile;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
|
|
||||||
pinMode(PIN_SD_CS, OUTPUT);
|
pinMode(PIN_SD_CS, OUTPUT);
|
||||||
digitalWrite(PIN_SD_CS, HIGH);
|
digitalWrite(PIN_SD_CS, HIGH);
|
||||||
|
@ -9,9 +9,10 @@
|
|||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
bool loadConfig() {
|
bool loadConfig() {
|
||||||
File configFile = SPIFFS.open("/config.json", "r");
|
File configFile = LittleFS.open("/config.json", "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
Serial.println("Failed to open config file");
|
Serial.println("Failed to open config file");
|
||||||
return false;
|
return false;
|
||||||
@ -56,7 +57,7 @@ bool saveConfig() {
|
|||||||
doc["serverName"] = "api.example.com";
|
doc["serverName"] = "api.example.com";
|
||||||
doc["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";
|
doc["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";
|
||||||
|
|
||||||
File configFile = SPIFFS.open("/config.json", "w");
|
File configFile = LittleFS.open("/config.json", "w");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
Serial.println("Failed to open config file for writing");
|
Serial.println("Failed to open config file for writing");
|
||||||
return false;
|
return false;
|
||||||
@ -72,7 +73,7 @@ void setup() {
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println("Mounting FS...");
|
Serial.println("Mounting FS...");
|
||||||
|
|
||||||
if (!SPIFFS.begin()) {
|
if (!LittleFS.begin()) {
|
||||||
Serial.println("Failed to mount file system");
|
Serial.println("Failed to mount file system");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,10 @@ uart_do_write_char(const int uart_nr, char c)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-result"
|
||||||
write(uart_nr + 1, &c, 1);
|
write(uart_nr + 1, &c, 1);
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
w = true;
|
w = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@
|
|||||||
|
|
||||||
#define SPIFFS_FILE_NAME "spiffs.bin"
|
#define SPIFFS_FILE_NAME "spiffs.bin"
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
FS SPIFFS(nullptr);
|
FS SPIFFS(nullptr);
|
||||||
|
|
||||||
SpiffsMock::SpiffsMock(ssize_t fs_size, size_t fs_block, size_t fs_page, const String& storage)
|
SpiffsMock::SpiffsMock(ssize_t fs_size, size_t fs_block, size_t fs_page, const String& storage)
|
||||||
@ -126,3 +129,6 @@ void SpiffsMock::save ()
|
|||||||
if (::close(fs) == -1)
|
if (::close(fs) == -1)
|
||||||
fprintf(stderr, "SPIFFS: closing %s: %s\n", m_storage.c_str(), strerror(errno));
|
fprintf(stderr, "SPIFFS: closing %s: %s\n", m_storage.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
@ -16,15 +16,16 @@
|
|||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include "../common/spiffs_mock.h"
|
#include <LittleFS.h>
|
||||||
|
#include "../common/littlefs_mock.h"
|
||||||
#include <spiffs/spiffs.h>
|
#include <spiffs/spiffs.h>
|
||||||
|
|
||||||
// Use a SPIFFS file because we can't instantiate a virtual class like Print
|
// Use a LittleFS file because we can't instantiate a virtual class like Print
|
||||||
TEST_CASE("Print::write overrides all compile properly", "[core][Print]")
|
TEST_CASE("Print::write overrides all compile properly", "[core][Print]")
|
||||||
{
|
{
|
||||||
SPIFFS_MOCK_DECLARE(64, 8, 512, "");
|
LITTLEFS_MOCK_DECLARE(64, 8, 512, "");
|
||||||
REQUIRE(SPIFFS.begin());
|
REQUIRE(LittleFS.begin());
|
||||||
auto p = SPIFFS.open("test.bin", "w");
|
auto p = LittleFS.open("test.bin", "w");
|
||||||
REQUIRE(p);
|
REQUIRE(p);
|
||||||
uint8_t uint8 = 1;
|
uint8_t uint8 = 1;
|
||||||
uint16_t uint16 = 2;
|
uint16_t uint16 = 2;
|
||||||
@ -56,7 +57,7 @@ TEST_CASE("Print::write overrides all compile properly", "[core][Print]")
|
|||||||
p.write(1);
|
p.write(1);
|
||||||
p.close();
|
p.close();
|
||||||
|
|
||||||
p = SPIFFS.open("test.bin", "r");
|
p = LittleFS.open("test.bin", "r");
|
||||||
REQUIRE(p);
|
REQUIRE(p);
|
||||||
uint8_t buff[16];
|
uint8_t buff[16];
|
||||||
int len = p.read(buff, 16);
|
int len = p.read(buff, 16);
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace spiffs_test {
|
namespace spiffs_test {
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
#define FSTYPE SPIFFS
|
#define FSTYPE SPIFFS
|
||||||
#define TESTPRE "SPIFFS - "
|
#define TESTPRE "SPIFFS - "
|
||||||
#define TESTPAT "[fs]"
|
#define TESTPAT "[fs]"
|
||||||
@ -54,6 +57,7 @@ TEST_CASE("SPIFFS checks the config object passed in", "[fs]")
|
|||||||
REQUIRE_FALSE(SPIFFS.setConfig(d));
|
REQUIRE_FALSE(SPIFFS.setConfig(d));
|
||||||
REQUIRE_FALSE(LittleFS.setConfig(l));
|
REQUIRE_FALSE(LittleFS.setConfig(l));
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
# resetmethod_menu_extra menus for additional reset methods
|
# resetmethod_menu_extra menus for additional reset methods
|
||||||
# crystalfreq/flashfreq_menu: menus for crystal/flash frequency selection
|
# crystalfreq/flashfreq_menu: menus for crystal/flash frequency selection
|
||||||
# flashmode_menu: menus for flashmode selection (dio/dout/qio/qout)
|
# flashmode_menu: menus for flashmode selection (dio/dout/qio/qout)
|
||||||
# 512K/1M/2M/4M/8M/16M: menus for flash & SPIFFS size
|
# 512K/1M/2M/4M/8M/16M: menus for flash & FS size
|
||||||
# lwip/lwip2 menus for available lwip versions
|
# lwip/lwip2 menus for available lwip versions
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
@ -613,7 +613,7 @@ boards = collections.OrderedDict([
|
|||||||
'~~~~~~~~~~~~~~~~~~~~~~~~~~',
|
'~~~~~~~~~~~~~~~~~~~~~~~~~~',
|
||||||
'',
|
'',
|
||||||
'- Card: "WEMOS D1 Mini Lite"',
|
'- Card: "WEMOS D1 Mini Lite"',
|
||||||
'- Flash Size: "1M (512K SPIFFS)"',
|
'- Flash Size: "1M (512K FS)"',
|
||||||
'- CPU Frequency: "80 Mhz"',
|
'- CPU Frequency: "80 Mhz"',
|
||||||
# '- Upload Speed: "230400"',
|
# '- Upload Speed: "230400"',
|
||||||
'',
|
'',
|
||||||
@ -696,7 +696,7 @@ boards = collections.OrderedDict([
|
|||||||
'opts': collections.OrderedDict([
|
'opts': collections.OrderedDict([
|
||||||
( '.build.board', 'WIFINFO' ),
|
( '.build.board', 'WIFINFO' ),
|
||||||
( '.build.variant', 'wifinfo' ),
|
( '.build.variant', 'wifinfo' ),
|
||||||
( '.menu.ESPModule.ESP07192', 'ESP07 (1M/192K SPIFFS)' ),
|
( '.menu.ESPModule.ESP07192', 'ESP07 (1M/192K FS)' ),
|
||||||
( '.menu.ESPModule.ESP07192.build.board', 'ESP8266_ESP07' ),
|
( '.menu.ESPModule.ESP07192.build.board', 'ESP8266_ESP07' ),
|
||||||
( '.menu.ESPModule.ESP07192.build.flash_size', '1M' ),
|
( '.menu.ESPModule.ESP07192.build.flash_size', '1M' ),
|
||||||
( '.menu.ESPModule.ESP07192.build.flash_ld', 'eagle.flash.1m192.ld' ),
|
( '.menu.ESPModule.ESP07192.build.flash_ld', 'eagle.flash.1m192.ld' ),
|
||||||
@ -704,7 +704,7 @@ boards = collections.OrderedDict([
|
|||||||
( '.menu.ESPModule.ESP07192.build.spiffs_end', '0xFB000' ),
|
( '.menu.ESPModule.ESP07192.build.spiffs_end', '0xFB000' ),
|
||||||
( '.menu.ESPModule.ESP07192.build.spiffs_blocksize', '4096' ),
|
( '.menu.ESPModule.ESP07192.build.spiffs_blocksize', '4096' ),
|
||||||
( '.menu.ESPModule.ESP07192.upload.maximum_size', '827376' ),
|
( '.menu.ESPModule.ESP07192.upload.maximum_size', '827376' ),
|
||||||
( '.menu.ESPModule.ESP12', 'ESP12 (4M/1M SPIFFS)' ),
|
( '.menu.ESPModule.ESP12', 'ESP12 (4M/1M FS)' ),
|
||||||
( '.menu.ESPModule.ESP12.build.board', 'ESP8266_ESP12' ),
|
( '.menu.ESPModule.ESP12.build.board', 'ESP8266_ESP12' ),
|
||||||
( '.menu.ESPModule.ESP12.build.flash_size', '4M' ),
|
( '.menu.ESPModule.ESP12.build.flash_size', '4M' ),
|
||||||
( '.menu.ESPModule.ESP12.build.flash_ld', 'eagle.flash.4m1m.ld' ),
|
( '.menu.ESPModule.ESP12.build.flash_ld', 'eagle.flash.4m1m.ld' ),
|
||||||
@ -1316,7 +1316,7 @@ def flash_map (flashsize_kb, fs_kb = 0):
|
|||||||
else:
|
else:
|
||||||
fs_blocksize = 8192
|
fs_blocksize = 8192
|
||||||
|
|
||||||
# Adjust SPIFFS_end to be a multiple of the block size
|
# Adjust FS_end to be a multiple of the block size
|
||||||
fs_end = fs_blocksize * (int)((fs_end - fs_start)/fs_blocksize) + fs_start;
|
fs_end = fs_blocksize * (int)((fs_end - fs_start)/fs_blocksize) + fs_start;
|
||||||
|
|
||||||
max_ota_size = min(max_upload_size, fs_start / 2) # =(max_upload_size+empty_size)/2
|
max_ota_size = min(max_upload_size, fs_start / 2) # =(max_upload_size+empty_size)/2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user