From 3733ece7e8c4ece1aaa99cef98dc9152bb277539 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Nunes Date: Fri, 20 Sep 2019 09:44:48 +0200 Subject: [PATCH] Allow Filesystem update via ESP8266HTTPUpdateServer (#3732) * Allow SPIFFS update via ESP8266HTTPUpdateServer This adds capability to update the SPIFFS image via the same mechansism as firmware in the ESP8266HTTPUpdateServer. It does not provide any dependency or linkage between firmware and spiffs image updating; they are each taken on their own, each followed by a reboot. (I wrote this before seeing the other PR for similar functionality; I like this a bit better, becaue it uses the available SPIFFS size, and does not hide magic numbers (U_SPIFFS) in the html...) (It also cleans up a stray \n from commit ace0622) * A simple filter * Review https://github.com/esp8266/Arduino/pull/3234#pullrequestreview-37773153 * Including suggestions for mobile first #3961 * SPIFFS rennamed to FS * including comments from @earlephihower * button renaming * missing #include for LittleFS * generic names as suggested by @d-a-v --- .../src/ESP8266HTTPUpdateServer-impl.h | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h index b543073f4..6761177a0 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include "StreamString.h" #include "ESP8266HTTPUpdateServer.h" @@ -10,11 +13,25 @@ namespace esp8266httpupdateserver { using namespace esp8266webserver; static const char serverIndex[] PROGMEM = - R"(
- - -
- )"; + R"( + + + + + + +
+ Firmware:
+ + +
+
+ FileSystem:
+ + +
+ + )"; static const char successResponse[] PROGMEM = "Update Success! Rebooting..."; @@ -75,9 +92,18 @@ void ESP8266HTTPUpdateServerTemplate::setup(ESP8266WebServerTemplate WiFiUDP::stopAll(); if (_serial_output) Serial.printf("Update: %s\n", upload.filename.c_str()); - uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; - if(!Update.begin(maxSketchSpace)){//start with max available size - _setUpdaterError(); + if (upload.name == "filesystem") { + size_t fsSize = ((size_t) &_FS_end - (size_t) &_FS_start); + SPIFFS.end(); + LittleFS.end(); + if (!Update.begin(fsSize, U_FS)){//start with max available size + if (_serial_output) Update.printError(Serial); + } + } else { + uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; + if (!Update.begin(maxSketchSpace, U_FLASH)){//start with max available size + _setUpdaterError(); + } } } else if(_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()){ if (_serial_output) Serial.printf(".");