From 6ed1e0fe526340e3d86d3134173fd262ef2f27c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laercio=20Mendon=C3=A7a?= Date: Mon, 3 Sep 2018 20:14:43 -0300 Subject: [PATCH] SPIFFS-WEBUPDATE --- .../src/ESP8266HTTPUpdateServer.cpp | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp index 25236294e2..30ace8df1d 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp @@ -6,15 +6,24 @@ #include "StreamString.h" #include "ESP8266HTTPUpdateServer.h" +extern "C" uint32_t _SPIFFS_start; +extern "C" uint32_t _SPIFFS_end; static const char serverIndex[] PROGMEM = - R"(
- - + R"( + + Firmware:
+ +
- )"; +
+ Spiffs:
+ + +
+ )"; static const char successResponse[] PROGMEM = - "Update Success! Rebooting...\n"; + "Update Success! Rebooting...\n"; ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug) { @@ -71,9 +80,16 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path, 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 == "spiffs") { + size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start); + if (!Update.begin(spiffsSize, U_SPIFFS)){//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("."); @@ -101,4 +117,4 @@ void ESP8266HTTPUpdateServer::_setUpdaterError() StreamString str; Update.printError(str); _updaterError = str.c_str(); -} +} \ No newline at end of file