微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ESP32 WebServer如何让服务器自动从远程IP服务器下载OTA bin文件并启动OTA进程

如何解决ESP32 WebServer如何让服务器自动从远程IP服务器下载OTA bin文件并启动OTA进程

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

我指的是 How to enable the server to automatically download files using arduino for ESP32 WebServer without using SPIFFS and instead using SDcard file,但它侧重于从 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);
      }
    }
  });

问候, 沙里克

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。