ESP32 Arduino: Updating firmware from the SPIFFS file system

#include "SPIFFS.h"
#include "Update.h"
 
void setup() {
 
   Serial.begin(115200);
 
   if(!SPIFFS.begin(true)){
        Serial.println("An Error has occurred while mounting SPIFFS");
        return;
   }
  
    File file = SPIFFS.open("/firmware.bin");
 
    if(!file){
        Serial.println("Failed to open file for reading");
        return;
    }
      
    Serial.println("Starting update..");
       
    size_t fileSize = file.size();
    if(!Update.begin(fileSize)){
      
       Serial.println("Cannot do the update");
       return;
    };
    Update.writeStream(file);
    if(Update.end()){
      
      Serial.println("Successful update"); 
    }else {
      
      Serial.println("Error Occurred: " + String(Update.getError()));
      return;
    }
    
    file.close();
    Serial.println("Reset in 4 seconds...");
    delay(4000);
    ESP.restart();
}
 
void loop() {}

Source: ESP32 Arduino: Updating firmware from the SPIFFS file system – techtutorialsx

ESP32 Arduino: Updating firmware from the SPIFFS file system was last modified: January 2nd, 2022 by Jovan Stosic

Leave a Reply