Skip to content

Allow SPIFFS update via ESP8266HTTPUpdateServer #3234

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 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
#include "StreamString.h"
#include "ESP8266HTTPUpdateServer.h"

extern "C" uint32_t _SPIFFS_start;
extern "C" uint32_t _SPIFFS_end;

static const char serverIndex[] PROGMEM =
R"(<html><body><form method='POST' action='' enctype='multipart/form-data'>
<input type='file' name='update'>
<input type='submit' value='Update'>
R"(<html><body>
<form method='POST' action='' enctype='multipart/form-data'>
Firmware:<br>
<input type='file' name='firmware'>
<input type='submit' value='Update Firmware'>
</form>
</body></html>\n)";
<form method='POST' action='' enctype='multipart/form-data'>
Spiffs:<br>
<input type='file' name='spiffs'>
Copy link
Contributor

Choose a reason for hiding this comment

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

What about to include accept='.bin' in both fields to filter a little?

<input type='submit' value='Update SPIFFS'>
</form>
</body></html>)";
static const char successResponse[] PROGMEM =
"<META http-equiv=\"refresh\" content=\"15;URL=\">Update Success! Rebooting...\n";

Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Should we call SPIFFS.end() here, or check that this is done by the caller?
In this default example this is likely to be not an issue, as we are resetting after the update. But may be an issue in other scenarios.

Copy link
Author

@sandeen sandeen May 12, 2017

Choose a reason for hiding this comment

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

Oh, interesting. The README does say Use this method before updating SPIFFS using OTA.
I didn't see anything like that in ./libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp either - should it get added to both?
With my filesystem developer hat on, yes, it seems crazy to be updating the storage behind a live, mounted filesystem, but I'm not that familiar with this particular situation.
I can add it and test a bit if you like.
Thanks,
-Eric

Copy link
Member

Choose a reason for hiding this comment

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

I think SPIFFS.end was only added recently, precisely for this use case. The libraries haven't been updated to take advantage of it, however. So updating the behavior of OTA libraries would indeed be welcome.

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(".");
Expand Down