Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP update server can handle flash and spiffs files (spiffs size lim… #2701

Closed
wants to merge 14 commits into from
18 changes: 13 additions & 5 deletions libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@


static const char serverIndex[] PROGMEM =
R"(<html><body><form method='POST' action='' enctype='multipart/form-data'>
R"(<html><body><form method='POST' action='?cmd=0' enctype='multipart/form-data'>
<input type='hidden' name='cmd' value='0'>
<input type='file' name='update'>
<input type='submit' value='Update'>
<input type='submit' value='Update Flash'>
</form>
<form method='POST' action='?cmd=100' enctype='multipart/form-data'>
<input type='hidden' name='cmd' value='100'>
<input type='file' name='update'>
<input type='submit' value='Update Spiffs'>
</form>
</body></html>)";
static const char successResponse[] PROGMEM =
Expand Down Expand Up @@ -44,7 +50,8 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& path
return _server->requestAuthentication();
if (Update.hasError()) {
_server->send(200, F("text/html"), String(F("Update error: ")) + _updaterError);
} else {
} else {
_command = _server->arg("cmd").toInt();
_server->client().setNoDelay(true);
_server->send_P(200, PSTR("text/html"), successResponse);
delay(100);
Expand All @@ -71,8 +78,9 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const String& 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
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
_command = _server->arg("cmd").toInt();
if(!Update.begin(maxSketchSpace, _command)){//start with max available size
_setUpdaterError();
}
} else if(_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ESP8266HTTPUpdateServer
String _password;
bool _authenticated;
String _updaterError;
int _command;
};


Expand Down