Forum: Mikrocontroller und Digitale Elektronik Hilfe beim Update vom Filesystem ESP32/8266


von test (Gast)


Lesenswert?

Hallo,
ich moechte meinen ESP32 und ESP8266 ueber eine Datei im Filesystem 
updaten, dazu habe ich folgende Funktion geschrieben
1
void performUpdate(Stream &updateSource, size_t updateSize) {
2
   if (Update.begin(updateSize)) {      
3
      size_t written = Update.writeStream(updateSource);
4
      if (written == updateSize) {
5
         Serial.println("Written : " + String(written) + " successfully");
6
      }
7
      else {
8
         Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
9
      }
10
      if (Update.end()) {
11
         Serial.println(F("OTA done!"));
12
         if (Update.isFinished()) {
13
            Serial.println(F("Update successfully completed. Rebooting."));
14
         }
15
         else {
16
            Serial.println(F("Update not finished? Something went wrong!"));
17
         }
18
      }
19
      else {
20
         Serial.println("Error Occurred. Error #: " + String(Update.getError()));
21
      }
22
23
   }
24
   else
25
   {
26
      Serial.println(F("Not enough space to begin OTA"));
27
   }
28
}
29
30
void updateFromFS() {
31
   File updateBin = LittleFS.open("/update.bin","r");
32
   if (updateBin) {
33
      if(updateBin.isDirectory()){
34
         Serial.println("Error, update.bin is not a file");
35
         updateBin.close();
36
         return;
37
      }
38
39
      size_t updateSize = updateBin.size();
40
41
      if (updateSize > 0) {
42
         Serial.println("Try to start update");
43
         performUpdate(updateBin, updateSize);
44
      }
45
      else {
46
         Serial.println("Error, file is empty");
47
      }
48
49
      updateBin.close();
50
    
51
      // whe finished remove the binary from sd card to indicate end of the process
52
      LittleFS.remove("/update.bin");      
53
   }
54
   else {
55
      Serial.println("Could not load update.bin from sd root");
56
   }
57
}

Allerdings stuerzt dabei mein ESP32 und auch der ESP8266 ab - macht 
einen reboot.

Was mache ich falsch bei der VErwendung?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.