Arduino Esp8266 LittleFS上传更新

Arduino Esp8266 LittleFS上传更新,arduino,esp8266,arduino-esp8266,platformio,Arduino,Esp8266,Arduino Esp8266,Platformio,在我的ESP8266上,我运行一个小型Web服务器。在一个页面上,我能够上传固件的二进制文件并点击更新。Esp8266更新其代码并重新启动。然后运行新代码。到现在为止,一直都还不错。 在ESP8266上的Web服务器中,我需要提供一些文件,如index.html和一些javascript文件。我将这些文件打包到数据目录中,并创建了一个LittleFS分区。我可以在Platformio中进行更改并上传littleFS.bin,重新启动后,新文件将被提供 现在我想上传littleFS.bin到ESP

在我的ESP8266上,我运行一个小型Web服务器。在一个页面上,我能够上传固件的二进制文件并点击更新。Esp8266更新其代码并重新启动。然后运行新代码。到现在为止,一直都还不错。 在ESP8266上的Web服务器中,我需要提供一些文件,如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]:没有足够的空间

有人已经实现了什么吗? 非常感谢。 尼基

尝试替换

uint32_t maxSketchSpace = 1300000;


这是因为您硬编码了空间。然后计算剩余的自由空间。类似于(文件系统总空间-已用空间=剩余可用空间)。因此,它将获得实际可用空间


这就是它的工作原理。

如果您能扩展您的答案并解释它修复了什么以及为什么,这样其他人就可以理解解决方案,而不必盲目复制和粘贴。非常好,谢谢。但是为什么呢?你能给我一些线索,为什么这样做?非常感谢。
uint32_t maxSketchSpace = ((size_t) &_FS_end - (size_t) &_FS_start);