Arduino Esp8266 LittleFS 上传更新

Arduino Esp8266 LittleFS upload for updating

在我的 ESP8266 上我 运行 一个小型网络服务器。在一页上,我可以上传固件的二进制文件并点击更新。 Esp8266 更新代码并重启。此后,新代码为 运行。到目前为止,一切都很好。 在我的 ESP8266 网络服务器中,我提供了一些文件,例如 index.html 和一些 javascript 文件。我将这些文件打包到数据目录中,并创建了一个 LittleFS 分区。我可以在 Platformio 中进行更改并上传 littleFS.bin 并在重新启动后提供新文件。

现在我想将 littleFS.bin 也上传到 ESP8266 并通过网站进行更新。但这失败了。

这是我试过的一些代码,但我一直收到错误消息。

  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);
    }

它抱怨错误[4]:不够Space

有人已经实现了吗? 谢谢 尼基

尝试替换

uint32_t maxSketchSpace = 1300000;

uint32_t maxSketchSpace = ((size_t) &_FS_end - (size_t) &_FS_start);

这是因为您对 space 进行了硬编码。和享受者计算剩余的免费space。类似于(文件系统总计 Space - 使用 Space = 剩余可用 space)。所以它将获得实际可用的 space.

这就是它的工作原理。