Hallo,
ich moechte meinen ESP32 und ESP8266 ueber eine Datei im Filesystem updaten, dazu habe ich folgende Funktion geschrieben
void performUpdate(Stream &updateSource, size_t updateSize) {
if (Update.begin(updateSize)) {
size_t written = Update.writeStream(updateSource);
if (written == updateSize) {
Serial.println("Written : " + String(written) + " successfully");
}
else {
Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
}
if (Update.end()) {
Serial.println(F("OTA done!"));
if (Update.isFinished()) {
Serial.println(F("Update successfully completed. Rebooting."));
}
else {
Serial.println(F("Update not finished? Something went wrong!"));
}
}
else {
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
}
}
else
{
Serial.println(F("Not enough space to begin OTA"));
}
}
void updateFromFS() {
File updateBin = LittleFS.open("/update.bin","r");
if (updateBin) {
if(updateBin.isDirectory()){
Serial.println("Error, update.bin is not a file");
updateBin.close();
return;
}
size_t updateSize = updateBin.size();
if (updateSize > 0) {
Serial.println("Try to start update");
performUpdate(updateBin, updateSize);
}
else {
Serial.println("Error, file is empty");
}
updateBin.close();
// whe finished remove the binary from sd card to indicate end of the process
LittleFS.remove("/update.bin");
}
else {
Serial.println("Could not load update.bin from sd root");
}
}
Allerdings stuerzt dabei mein ESP32 und auch der ESP8266 ab - macht einen reboot.
Was mache ich falsch bei der VErwendung?