Skip to content

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

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

Closed
wants to merge 14 commits into from
Closed
12 changes: 10 additions & 2 deletions libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@

const char* ESP8266HTTPUpdateServer::_serverIndex =
R"(<html><body><form method='POST' action='' 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='' 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>)";
const char* ESP8266HTTPUpdateServer::_failedResponse = R"(Update Failed!)";
const char* ESP8266HTTPUpdateServer::_successResponse = "<META http-equiv=\"refresh\" content=\"15;URL=\">Update Success! Rebooting...";
int _command;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make the int _command a class member in ESP8266HTTPUpdateServer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PA4WD, do you need help with that?
This PR will be a great improvement to this feature!


ESP8266HTTPUpdateServer::ESP8266HTTPUpdateServer(bool serial_debug)
{
Expand Down Expand Up @@ -41,6 +48,7 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path,
_server->on(path, HTTP_POST, [&](){
if(!_authenticated)
return _server->requestAuthentication();
_command = _server->arg("cmd").toInt();
_server->send(200, "text/html", Update.hasError() ? _failedResponse : _successResponse);
ESP.restart();
},[&](){
Expand All @@ -62,7 +70,7 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path,
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
if(!Update.begin(maxSketchSpace, _command)){//start with max available size
if (_serial_output) Update.printError(Serial);
}
} else if(_authenticated && upload.status == UPLOAD_FILE_WRITE){
Expand Down