0

On my ESP8266 I run a small Webserver. On one page I am able to upload a binary file for the firmware and hit update. The Esp8266 updates its code and makes a reboot. After this the new code is run. So far so good. In my webserver on the ESP8266 I have some files to provide like index.html and some javascript files. I packed these files in the data directory and created a LittleFS partition. I can make changes in Platformio and upload the littleFS.bin and after a reboot the new files are served.

Now I would like to upload the littleFS.bin also to the ESP8266 an make an update via the website. But this fails.

Here is some code I tried but I get Error messages all the time.

  server.on("/updatespiffs", HTTP_POST, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/plain", (Update.hasError()) ? "spiffsFAIL" : "spiffsOK");
    delay(5000);
    ESP.restart();
  }, []() {
    HTTPUpload& upload = server.upload();
    if (upload.status == UPLOAD_FILE_START) {
      Serial.setDebugOutput(true);
      WiFiUDP::stopAll();
      Serial.printf("Update: %s\n", upload.filename.c_str());
      LittleFS.end();

      uint32_t maxSketchSpace = 1300000;
      if (!Update.begin(maxSketchSpace, U_FS)) { //start with max available size
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_WRITE) {
      uint32_t xy = Update.write(upload.buf, upload.currentSize);
      if (xy != upload.currentSize) {
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_END) {
      if (Update.end(true)) { //true to set the size to the current progress
        Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
      } else {
        
        Update.printError(Serial);
      }
      Serial.setDebugOutput(false);
    }

It complains about ERROR[4]: Not Enough Space

Has anyone implemented something already? Thank you Niki

Niki
  • 13
  • 5

2 Answers2

1

This is because you hardcoded the space. and the enjoyneering calculate the remaining free space. something like (FileSystem Total Space - Used Space = Remaining available space). so it will get the actual available space.

Thats how it worked.

Atif Hussain
  • 19
  • 1
  • 5
-1

Try to replace

uint32_t maxSketchSpace = 1300000;

with

uint32_t maxSketchSpace = ((size_t) &_FS_end - (size_t) &_FS_start);
  • It would be useful if you could expand your answer and explain what it fixes and why, so that others can understand the solution without just blind copy-and-paste. – AlBlue Dec 22 '20 at 21:10
  • works perfect, thanks. But why? Can you give me some clue why this works? Thank you. – Niki Dec 24 '20 at 06:59