@@ -127,6 +127,8 @@ String HTTPUpdate::getLastErrorString(void)
127127 return " Verify Bin Header Failed" ;
128128 case HTTP_UE_BIN_FOR_WRONG_FLASH:
129129 return " New Binary Does Not Fit Flash Size" ;
130+ case HTTP_UE_NO_PARTITION:
131+ return " Partition Could Not be Found" ;
130132 }
131133
132134 return String ();
@@ -238,14 +240,25 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
238240 if (len > 0 ) {
239241 bool startUpdate = true ;
240242 if (spiffs) {
241- // To do size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start);
242- // To do if(len > (int) spiffsSize) {
243- // To do log_e("spiffsSize to low (%d) needed: %d\n", spiffsSize, len);
244- // To do startUpdate = false;
245- // To do }
243+ const esp_partition_t * _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL );
244+ if (!_partition){
245+ _lastError = HTTP_UE_NO_PARTITION;
246+ return HTTP_UPDATE_FAILED;
247+ }
248+
249+ if (len > _partition->size ) {
250+ log_e (" spiffsSize to low (%d) needed: %d\n " , _partition->size , len);
251+ startUpdate = false ;
252+ }
246253 } else {
247- if (len > (int ) ESP.getFreeSketchSpace ()) {
248- log_e (" FreeSketchSpace to low (%d) needed: %d\n " , ESP.getFreeSketchSpace (), len);
254+ int sketchFreeSpace = ESP.getFreeSketchSpace ();
255+ if (!sketchFreeSpace){
256+ _lastError = HTTP_UE_NO_PARTITION;
257+ return HTTP_UPDATE_FAILED;
258+ }
259+
260+ if (len > sketchFreeSpace) {
261+ log_e (" FreeSketchSpace to low (%d) needed: %d\n " , sketchFreeSpace, len);
249262 startUpdate = false ;
250263 }
251264 }
@@ -375,6 +388,8 @@ bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command)
375388 }
376389 }
377390
391+ // To do: the SHA256 could be checked if the server sends it
392+
378393 if (Update.writeStream (in) != size) {
379394 _lastError = Update.getError ();
380395 Update.printError (error);
0 commit comments