首页 > 解决方案 > ESP32 WebServer中如何使服务器自动从远程IP服务器下载OTA bin文件并启动OTA流程

问题描述

我试图了解在下载托管在远程 IP(网络内)中的 bin 文件后是否有可能(如果是,如何)继续 OTA 过程?该代码将在 ESP32 上运行。(编辑)我正在尝试介绍一种自我 OTA 更新的方法。它也可以通过点击 esp 网络服务器的端点来触发(通过 mqtt、http 等)

我指的是如何使服务器能够使用 arduino for ESP32 WebServer 自动下载文件,而不使用 SPIFFS,而是使用 SDcard 文件,但它侧重于从 sd 卡而不是网络下载。

目前,我正在关注https://randomnerdtutorials.com/esp32-over-the-air-ota-programming/中提到的代码,该代码目前处理通过浏览器上传 bin 文件,我正在尝试自动化。如果我能以某种方式以编程方式用数据触发这部分代码,那么我认为我的问题仍然会得到解决。

server.on("/update", HTTP_POST, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
    ESP.restart();
  }, []() {
    HTTPUpload& upload = server.upload();
    if (upload.status == UPLOAD_FILE_START) {
      Serial.printf("Update: %s\n", upload.filename.c_str());
      if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_WRITE) {
      /* flashing firmware to ESP*/
      if (Update.write(upload.buf, upload.currentSize) != 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);
      }
    }
  });

问候, 沙里克

标签: arduinoesp8266esp32ota

解决方案


推荐阅读