diff --git a/src/WebOTA.cpp b/src/WebOTA.cpp
index de09280..539c22e 100644
--- a/src/WebOTA.cpp
+++ b/src/WebOTA.cpp
@@ -20,6 +20,12 @@ char MDNS_GLOBAL[30];
// Index page
const char* indexPage = "
WebOTA
";
+long max_sketch_size() {
+ long ret = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
+
+ return ret;
+}
+
// Get the HTML for the sketch upload page
String get_ota_html() {
String ota_html = "";
@@ -31,6 +37,7 @@ String get_ota_html() {
ota_html += " \n";
ota_html += "\n";
ota_html += "\n";
+ ota_html += "Max sketch size: " + (String)max_sketch_size() + "
\n";
ota_html += "\n";
ota_html += "
\n";
ota_html += "
\n";
@@ -148,7 +155,11 @@ int add_http_routes(WebServer *server, const char *path) {
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Firmware update initiated: %s\r\n", upload.filename.c_str());
- if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
+
+ //uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
+ uint32_t maxSketchSpace = max_sketch_size();
+
+ if (!Update.begin(maxSketchSpace)) { //start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {