问题描述
在ESP8266上,我运行一个小型Web服务器。在一页上,我可以上传固件的二进制文件并点击更新。 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]:空间不足
有人已经实施了吗? 谢谢 妮基
解决方法
这是因为您对空间进行了硬编码。然后享受计算剩余的可用空间。类似于(文件系统总空间 - 已用空间 = 剩余可用空间)。所以它会得到实际的可用空间。
这就是它的工作原理。
,尝试更换
uint32_t maxSketchSpace = 1300000;
与
uint32_t maxSketchSpace = ((size_t) &_FS_end - (size_t) &_FS_start);