Skip to content

Commit 3733ece

Browse files
cavernad-a-v
authored andcommitted
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 #3234 (review) * 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
1 parent a10e02e commit 3733ece

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h

+34-8
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,35 @@
33
#include <WiFiServer.h>
44
#include <ESP8266WebServer.h>
55
#include <WiFiUdp.h>
6+
#include <flash_hal.h>
7+
#include <FS.h>
8+
#include <LittleFS.h>
69
#include "StreamString.h"
710
#include "ESP8266HTTPUpdateServer.h"
811

912
namespace esp8266httpupdateserver {
1013
using namespace esp8266webserver;
1114

1215
static const char serverIndex[] PROGMEM =
13-
R"(<html><body><form method='POST' action='' enctype='multipart/form-data'>
14-
<input type='file' name='update'>
15-
<input type='submit' value='Update'>
16-
</form>
17-
</body></html>)";
16+
R"(<!DOCTYPE html>
17+
<html lang='en'>
18+
<head>
19+
<meta charset='utf-8'>
20+
<meta name='viewport' content='width=device-width,initial-scale=1'/>
21+
</head>
22+
<body>
23+
<form method='POST' action='' enctype='multipart/form-data'>
24+
Firmware:<br>
25+
<input type='file' accept='.bin' name='firmware'>
26+
<input type='submit' value='Update Firmware'>
27+
</form>
28+
<form method='POST' action='' enctype='multipart/form-data'>
29+
FileSystem:<br>
30+
<input type='file' accept='.bin' name='filesystem'>
31+
<input type='submit' value='Update FileSystem'>
32+
</form>
33+
</body>
34+
</html>)";
1835
static const char successResponse[] PROGMEM =
1936
"<META http-equiv=\"refresh\" content=\"15;URL=/\">Update Success! Rebooting...";
2037

@@ -75,9 +92,18 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
7592
WiFiUDP::stopAll();
7693
if (_serial_output)
7794
Serial.printf("Update: %s\n", upload.filename.c_str());
78-
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
79-
if(!Update.begin(maxSketchSpace)){//start with max available size
80-
_setUpdaterError();
95+
if (upload.name == "filesystem") {
96+
size_t fsSize = ((size_t) &_FS_end - (size_t) &_FS_start);
97+
SPIFFS.end();
98+
LittleFS.end();
99+
if (!Update.begin(fsSize, U_FS)){//start with max available size
100+
if (_serial_output) Update.printError(Serial);
101+
}
102+
} else {
103+
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
104+
if (!Update.begin(maxSketchSpace, U_FLASH)){//start with max available size
105+
_setUpdaterError();
106+
}
81107
}
82108
} else if(_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()){
83109
if (_serial_output) Serial.printf(".");

0 commit comments

Comments
 (0)