@@ -118,6 +118,8 @@ String HTTPUpdate::getLastErrorString(void)
118
118
return " Verify Bin Header Failed" ;
119
119
case HTTP_UE_BIN_FOR_WRONG_FLASH:
120
120
return " New Binary Does Not Fit Flash Size" ;
121
+ case HTTP_UE_NO_PARTITION:
122
+ return " Partition Could Not be Found" ;
121
123
}
122
124
123
125
return String ();
@@ -229,14 +231,25 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
229
231
if (len > 0 ) {
230
232
bool startUpdate = true ;
231
233
if (spiffs) {
232
- // To do size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start);
233
- // To do if(len > (int) spiffsSize) {
234
- // To do log_e("spiffsSize to low (%d) needed: %d\n", spiffsSize, len);
235
- // To do startUpdate = false;
236
- // To do }
234
+ const esp_partition_t * _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL );
235
+ if (!_partition){
236
+ _lastError = HTTP_UE_NO_PARTITION;
237
+ return HTTP_UPDATE_FAILED;
238
+ }
239
+
240
+ if (len > _partition->size ) {
241
+ log_e (" spiffsSize to low (%d) needed: %d\n " , _partition->size , len);
242
+ startUpdate = false ;
243
+ }
237
244
} else {
238
- if (len > (int ) ESP.getFreeSketchSpace ()) {
239
- log_e (" FreeSketchSpace to low (%d) needed: %d\n " , ESP.getFreeSketchSpace (), len);
245
+ const esp_partition_t * _partition = esp_ota_get_next_update_partition (NULL );
246
+ if (!_partition){
247
+ _lastError = HTTP_UE_NO_PARTITION;
248
+ return HTTP_UPDATE_FAILED;
249
+ }
250
+
251
+ if (len > _partition->size ) {
252
+ log_e (" FreeSketchSpace to low (%d) needed: %d\n " , _partition->size , len);
240
253
startUpdate = false ;
241
254
}
242
255
}
@@ -366,6 +379,10 @@ bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command)
366
379
}
367
380
}
368
381
382
+ // To do: the SHA256 could be checked if the server sends it
383
+
384
+ delay (0 );
385
+
369
386
if (Update.writeStream (in) != size) {
370
387
_lastError = Update.getError ();
371
388
Update.printError (error);
0 commit comments