Skip to content

Commit 9e629e7

Browse files
author
Jeroen88
committed
Rewriting ESP.getFreeSketchSpace(), moving code from HTTPUpdate.cpp
1 parent 572b013 commit 9e629e7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

cores/esp32/Esp.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@ uint32_t EspClass::getSketchSize () {
169169
}
170170

171171
uint32_t EspClass::getFreeSketchSpace () {
172-
return sketchSize(SKETCH_SIZE_FREE);
172+
const esp_partition_t* _partition = esp_ota_get_next_update_partition(NULL);
173+
if(!_partition){
174+
return 0;
175+
}
176+
177+
return _partition->size;
173178
}
174179

175180
uint8_t EspClass::getChipRevision(void)

libraries/HTTPUpdate/src/HTTPUpdate.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
251251
startUpdate = false;
252252
}
253253
} else {
254-
const esp_partition_t* _partition = esp_ota_get_next_update_partition(NULL);
255-
if(!_partition){
254+
int sketchFreeSpace = ESP.getFreeSketchSpace();
255+
if(!sketchFreeSpace){
256256
_lastError = HTTP_UE_NO_PARTITION;
257257
return HTTP_UPDATE_FAILED;
258258
}
259259

260-
if(len > _partition->size) {
261-
log_e("FreeSketchSpace to low (%d) needed: %d\n", _partition->size, len);
260+
if(len > sketchFreeSpace) {
261+
log_e("FreeSketchSpace to low (%d) needed: %d\n", sketchFreeSpace, len);
262262
startUpdate = false;
263263
}
264264
}
@@ -390,8 +390,6 @@ bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command)
390390

391391
// To do: the SHA256 could be checked if the server sends it
392392

393-
delay(0);
394-
395393
if(Update.writeStream(in) != size) {
396394
_lastError = Update.getError();
397395
Update.printError(error);

0 commit comments

Comments
 (0)