chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

ESP32通過OTA無線局域網(wǎng)遠(yuǎn)程升級下載程序

jf_88434166 ? 來源:jf_88434166 ? 作者:jf_88434166 ? 2025-07-22 13:21 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

概要

ESP32 的 OTA(Over-The-Air)升級功能允許通過無線網(wǎng)絡(luò)Wi-Fi遠(yuǎn)程更新設(shè)備固件程序,無需物理連接(如 USB/UART)。比如ESP32設(shè)備在機(jī)殼內(nèi)部不好拆卸,人離設(shè)備比較遠(yuǎn),不好接線的環(huán)境可用到OTA方式給ESP32設(shè)備下載程序。為實(shí)現(xiàn)此功能每次更新程序的時候都要在代碼里面加入OTA的相關(guān)代碼。

遠(yuǎn)程OTA.jpg

創(chuàng)建ESP32-OTA無線局域網(wǎng)網(wǎng)頁版遠(yuǎn)程升級入口

打開Arduino IDE中自帶ESP32—OTAWebUpdater示例
在這里插入圖片描述

#include < WiFi.h >
#include < WiFiClient.h >
#include < WebServer.h >
#include < ESPmDNS.h >
#include < Update.h >

const char* host = "esp32";
const char* ssid = "YXDZ1";
const char* password = "YXDZ#2023#1";

WebServer server(80);

/*
 * Login page
 */

const char* loginIndex =
 "< form name='loginForm' >"
    "< table width='20%' bgcolor='A09F9F' align='center' >"
        "< tr >"
            "< td colspan=2 >"
                "< center >< font size=4 >ESP32 Login Page< /font >< /center >"
                "
"
            "< /td >"
            "
"
            "
"
        "< /tr >"
        "< tr >"
             "< td >Username:< /td >"
             "< td >< input type='text' size=25 name='userid' >
< /td >"
        "< /tr >"
        "
"
        "
"
        "< tr >"
            "< td >Password:< /td >"
            "< td >< input type='Password' size=25 name='pwd' >
< /td >"
            "
"
            "
"
        "< /tr >"
        "< tr >"
            "< td >< input type='submit' onclick='check(this.form)' value='Login' >< /td >"
        "< /tr >"
    "< /table >"
"< /form >"
"< script >"
    "function check(form)"
    "{"
    "if(form.userid.value=='ESP32-OTA' && form.pwd.value=='ESP32-OTA')"
    "{"
    "window.open('/serverIndex')"
    "}"
    "else"
    "{"
    " alert('Error Password or Username')/*displays error message*/"
    "}"
    "}"
"< /script >";

/*
 * Server Index Page
 */

const char* serverIndex =
"< script src='http://www.brongaenegriffin.com/images/chaijie_default.png' >< /script >"
"< form method='POST' action='#' enctype='multipart/form-data' id='upload_form' >"
   "< input type='file' name='update' >"
        "< input type='submit' value='Update' >"
    "< /form >"
 "progress: 0%"
 "< script >"
  "$('form').submit(function(e){"
  "e.preventDefault();"
  "var form = $('#upload_form')[0];"
  "var data = new FormData(form);"
  " $.ajax({"
  "url: '/update',"
  "type: 'POST',"
  "data: data,"
  "contentType: false,"
  "processData:false,"
  "xhr: function() {"
  "var xhr = new window.XMLHttpRequest();"
  "xhr.upload.addEventListener('progress', function(evt) {"
  "if (evt.lengthComputable) {"
  "var per = evt.loaded / evt.total;"
  "$('#prg').html('progress: ' + Math.round(per*100) + '%');"
  "}"
  "}, false);"
  "return xhr;"
  "},"
  "success:function(d, s) {"
  "console.log('success!')"
 "},"
 "error: function (a, b, c) {"
 "}"
 "});"
 "});"
 "< /script >";

/*
 * setup function
 */
void setup(void) {
  Serial.begin(115200);

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  /*use mdns for host name resolution*/
  if (!MDNS.begin(host)) { //http://esp32.local
    Serial.println("Error setting up MDNS responder!");
    while (1) {
      delay(1000);
    }
  }
  Serial.println("mDNS responder started");
  /*return index page which is stored in serverIndex */
  server.on("/", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", loginIndex);
  });
  server.on("/serverIndex", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", serverIndex);
  });
  /*handling uploading firmware file */
  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: %sn", 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: %unRebooting...n", upload.totalSize);
      } else {
        Update.printError(Serial);
      }
    }
  });
  server.begin();
}

void loop(void) {
  server.handleClient();
  delay(1);
}

并對其中的代碼做如下更改:
給ESP32開發(fā)板連接到自己電腦所在的局域網(wǎng)的路由器WIFI上,填上WIFI名稱ssis和密碼password

const char* host = "esp32";
const char* ssid = "YXDZ1";
const char* password = "YXDZ#2023#1";

host為ESP32作為Web服務(wù)器時,將ESP32以易記的主機(jī)名(如esp32.local)廣播到局域網(wǎng),其他設(shè)備可直接通過該名稱訪問,用戶可通過http://esp32.local直接訪問,無需記憶IP地址

const char* host = "esp32";

  /*use mdns for host name resolution*/
  if (!MDNS.begin(host)) { //http://esp32.local
    Serial.println("Error setting up MDNS responder!");
    while (1) {
      delay(1000);
    }
  }

更改好OTA無線局域網(wǎng)網(wǎng)頁版入口的用戶名和密碼,這里都更改為ESP32-OTA

"if(form.userid.value=='ESP32-OTA' && form.pwd.value=='ESP32-OTA')"

通過有線方式連接電腦和ESP32開發(fā)板,并把代碼編譯通過先通過有線方式下載到ESP32開發(fā)板,讓開發(fā)板創(chuàng)建無線OTA遠(yuǎn)程升級網(wǎng)頁版入口
打開串口助手,按下ESP32開發(fā)板復(fù)位,會顯示出所連接的局域網(wǎng)的IP地址,mDNS域名訪問創(chuàng)建成功。
在這里插入圖片描述
在瀏覽器輸入IP地址或創(chuàng)建的http://esp32.local域名即可跳轉(zhuǎn)到OTA遠(yuǎn)程升級網(wǎng)頁版入口,輸入創(chuàng)建好的用戶名和密碼并登錄
在這里插入圖片描述
此時再跳轉(zhuǎn)到程序下載界面,選擇編譯好的程序文件并上傳到開發(fā)板內(nèi)
在這里插入圖片描述

創(chuàng)建一個ESP32開發(fā)板進(jìn)行OTA升級應(yīng)用程序示例

若要每次都要對ESP32開發(fā)板進(jìn)行OTA升級,新的應(yīng)用程序中都要加入上述OTA無線局域網(wǎng)網(wǎng)頁版遠(yuǎn)程升級入口的相關(guān)代碼。下面為一個ESP32開發(fā)板GPIO2引腳上的閃燈程序的代碼,并加入了OTA的相關(guān)代碼,然后對OTA部分的代碼進(jìn)行上述一樣的更改。

#include < WiFi.h >
#include < WiFiClient.h >
#include < WebServer.h >
#include < ESPmDNS.h >
#include < Update.h >

const char* host = "esp32";
const char* ssid = "YXDZ1";
const char* password = "YXDZ#2023#1";

//variabls to blink without delay:
const int led = 2;
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 1000;           // interval at which to blink (milliseconds)
int ledState = LOW;             // ledState used to set the LED

WebServer server(80);

/*
 * Login page
 */

const char* loginIndex = 
 "< form name='loginForm' >"
    "< table width='20%' bgcolor='A09F9F' align='center' >"
        "< tr >"
            "< td colspan=2 >"
                "< center >< font size=4 >ESP32 Login Page< /font >< /center >"
                "
"
            "< /td >"
            "
"
            "
"
        "< /tr >"
        "< td >Username:< /td >"
        "< td >< input type='text' size=25 name='userid' >
< /td >"
        "< /tr >"
        "
"
        "
"
        "< tr >"
            "< td >Password:< /td >"
            "< td >< input type='Password' size=25 name='pwd' >
< /td >"
            "
"
            "
"
        "< /tr >"
        "< tr >"
            "< td >< input type='submit' onclick='check(this.form)' value='Login' >< /td >"
        "< /tr >"
    "< /table >"
"< /form >"
"< script >"
    "function check(form)"
    "{"
    "if(form.userid.value=='ESP32-OTA' && form.pwd.value=='ESP32-OTA')"
    "{"
    "window.open('/serverIndex')"
    "}"
    "else"
    "{"
    " alert('Error Password or Username')/*displays error message*/"
    "}"
    "}"
"< /script >";
 
/*
 * Server Index Page
 */
 
const char* serverIndex = 
"< script src='http://www.brongaenegriffin.com/images/chaijie_default.png' >< /script >"
"< form method='POST' action='#' enctype='multipart/form-data' id='upload_form' >"
   "< input type='file' name='update' >"
        "< input type='submit' value='Update' >"
    "< /form >"
 "progress: 0%"
 "< script >"
  "$('form').submit(function(e){"
  "e.preventDefault();"
  "var form = $('#upload_form')[0];"
  "var data = new FormData(form);"
  " $.ajax({"
  "url: '/update',"
  "type: 'POST',"
  "data: data,"
  "contentType: false,"
  "processData:false,"
  "xhr: function() {"
  "var xhr = new window.XMLHttpRequest();"
  "xhr.upload.addEventListener('progress', function(evt) {"
  "if (evt.lengthComputable) {"
  "var per = evt.loaded / evt.total;"
  "$('#prg').html('progress: ' + Math.round(per*100) + '%');"
  "}"
  "}, false);"
  "return xhr;"
  "},"
  "success:function(d, s) {"
  "console.log('success!')" 
 "},"
 "error: function (a, b, c) {"
 "}"
 "});"
 "});"
 "< /script >";

/*
 * setup function
 */
void setup(void) {
  pinMode(led, OUTPUT);
  
  Serial.begin(115200);

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  /*use mdns for host name resolution*/
  if (!MDNS.begin(host)) { //http://esp32.local
    Serial.println("Error setting up MDNS responder!");
    while (1) {
      delay(1000);
    }
  }
  Serial.println("mDNS responder started");
  /*return index page which is stored in serverIndex */
  server.on("/", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", loginIndex);
  });
  server.on("/serverIndex", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", serverIndex);
  });
  /*handling uploading firmware file */
  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: %sn", 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: %unRebooting...n", upload.totalSize);
      } else {
        Update.printError(Serial);
      }
    }
  });
  server.begin();
}

void loop(void) {
  server.handleClient();
  delay(1);

  //loop to blink without delay
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    ledState = not(ledState);

    // set the LED with the ledState of the variable:
    digitalWrite(led, ledState);
  }
}

ESP32開發(fā)板OTA升級下載應(yīng)用程序

編譯并導(dǎo)出可供OTA升級下載的二進(jìn)制bin應(yīng)用程序文件
在這里插入圖片描述
在項(xiàng)目文件夾下的build文件夾里可看到可供下載的bin應(yīng)用程序文件
在這里插入圖片描述
進(jìn)入OTA無線局域網(wǎng)網(wǎng)頁版遠(yuǎn)程升級入口,打開應(yīng)用程序bin文件,并對ESP32開發(fā)板進(jìn)行遠(yuǎn)程下載程序

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • 無線局域網(wǎng)
    +關(guān)注

    關(guān)注

    1

    文章

    245

    瀏覽量

    30906
  • 程序
    +關(guān)注

    關(guān)注

    117

    文章

    3832

    瀏覽量

    84354
  • OTA
    OTA
    +關(guān)注

    關(guān)注

    7

    文章

    623

    瀏覽量

    37554
  • ESP32
    +關(guān)注

    關(guān)注

    21

    文章

    1044

    瀏覽量

    20297
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點(diǎn)推薦

    GD32單片機(jī)STM32遠(yuǎn)程下載手機(jī)程序升級固件下載局域網(wǎng)網(wǎng)頁升級工具

    GD32、STM32單片機(jī),是我們最常見的一種MCU。通常我們在使用STM32單片機(jī)都會遇到程序在線升級下載的問題。使用該方法可以完成手機(jī)網(wǎng)頁在線程序
    的頭像 發(fā)表于 11-09 12:31 ?3092次閱讀
    GD32單片機(jī)STM32<b class='flag-5'>遠(yuǎn)程</b><b class='flag-5'>下載</b>手機(jī)<b class='flag-5'>程序</b><b class='flag-5'>升級</b>固件<b class='flag-5'>下載</b><b class='flag-5'>局域網(wǎng)</b>網(wǎng)頁<b class='flag-5'>升級</b>工具

    淺析思科無線局域網(wǎng)

    思科無線局域網(wǎng)(WLAN)基礎(chǔ)?! ?b class='flag-5'>無線局域網(wǎng)(WLAN)  11.1 WLAN基礎(chǔ)  WLAN(Wireless Local Area Network,
    發(fā)表于 07-01 07:04

    嵌人式系統(tǒng)的無線局域網(wǎng)接入怎么實(shí)現(xiàn)?

    設(shè)備驅(qū)動的深入理解和分析,成功地移植在Atmel 9261 ARM處理器上。實(shí)現(xiàn)了嵌人式系統(tǒng)的無線局域網(wǎng)接入。利用該平臺,可以進(jìn)一步設(shè)計(jì)完善醫(yī)用伽馬相機(jī)和小型SPECT設(shè)備的手持?jǐn)?shù)據(jù)采集系統(tǒng),使得控制人員能夠遠(yuǎn)離數(shù)據(jù)采集現(xiàn)場,而通過遠(yuǎn)程
    發(fā)表于 03-06 06:27

    樂鑫ESP32空中下載(OTA)解決方案實(shí)操

    前言 OTA(Over-the-AirTechnology)即空中下載技術(shù),是通過移動通信的空中接口實(shí)現(xiàn)對移動終端設(shè)備及SIM卡數(shù)據(jù)進(jìn)行遠(yuǎn)程管理的技術(shù)。
    發(fā)表于 06-30 10:39

    OTA的具體應(yīng)用場景及遠(yuǎn)程升級遠(yuǎn)程的含義具體是什么?

    OTA遠(yuǎn)程升級一直有一個疑問,希望各位道友解答一下。不勝感激疑問1通過看官方的OTA升級的文檔
    發(fā)表于 11-14 14:21

    如何用esp32組建局域網(wǎng)?

    大家好,我想用esp32組建一個局域網(wǎng),請大家?guī)臀覅⒖家幌?,要求如?一個局域網(wǎng)內(nèi)數(shù)量不超過100臺。一臺主機(jī),可以同其他的設(shè)備通訊,其余均為從機(jī),只能和主機(jī)通訊,從機(jī)之間不能直接通訊。通訊的有效
    發(fā)表于 03-09 08:02

    無線局域網(wǎng)(WLAN)是什么?

    據(jù)傳輸。   WLAN 的工作原理   無線局域網(wǎng)的工作原理是通過發(fā)送和接收無線電信號來完成數(shù)據(jù)傳輸。接入點(diǎn)將有線網(wǎng)絡(luò)連接到無線網(wǎng)絡(luò),允許
    發(fā)表于 05-17 17:11

    GD32單片機(jī)STM32遠(yuǎn)程下載手機(jī)程序升級固件下載局域網(wǎng)網(wǎng)頁升級工具

    ,即可瀏覽到上傳的文件。點(diǎn)擊文件后面對應(yīng)的Flash按鈕即可完成STM32單片機(jī)的在線升級。 該服務(wù)器還支持FTP方式遠(yuǎn)程下載固件的功能,能夠完成局域網(wǎng)、互聯(lián)網(wǎng)的
    發(fā)表于 11-10 15:03

    無線局域網(wǎng)簡介

    無線局域網(wǎng)無線局域網(wǎng)絡(luò)(Wireless Local Area Networks; WLAN)是相當(dāng)便利的數(shù)據(jù)傳輸系統(tǒng),它利用射頻(Radio Frequency; RF)的技術(shù),
    發(fā)表于 11-24 03:21 ?2570次閱讀

    淺談無線局域網(wǎng)的優(yōu)點(diǎn)

    無線局域網(wǎng),其英文縮寫為WLAN。無線局域網(wǎng)無線通信技術(shù)與網(wǎng)絡(luò)技術(shù)相結(jié)合的產(chǎn)物。從專業(yè)角度講,無線
    發(fā)表于 11-14 15:51 ?3390次閱讀

    解答無線局域網(wǎng)該如何設(shè)置

    近些年來,網(wǎng)絡(luò)技術(shù)發(fā)展日新月異,隨著無線技術(shù)的不斷發(fā)展,現(xiàn)在我們生活當(dāng)中的網(wǎng)絡(luò),以及從過去的局域網(wǎng)發(fā)展成現(xiàn)在的無線局域網(wǎng)無線
    發(fā)表于 11-14 19:17 ?4149次閱讀

    無線局域網(wǎng)的優(yōu)點(diǎn)有哪些

    無線局域網(wǎng)是計(jì)算機(jī)網(wǎng)絡(luò)與無線通信技術(shù)相結(jié)合的產(chǎn)物,無線局域網(wǎng)的基礎(chǔ)還是傳統(tǒng)的有線局域網(wǎng),是有線
    的頭像 發(fā)表于 01-10 08:56 ?1w次閱讀

    ESP32通信amp;局域網(wǎng)刺破

    ESP32局域網(wǎng)中通訊非常簡單,按照模塊的AT指令集發(fā)送指令即可。常規(guī)情況下,需要局域網(wǎng)內(nèi)部的IP與局域網(wǎng)外界通訊,需要穿透局域網(wǎng),此時需
    的頭像 發(fā)表于 02-13 13:38 ?2452次閱讀

    wlan是無線網(wǎng)還是局域網(wǎng) wlan包括哪些無線局域網(wǎng)協(xié)議

    WLAN是無線局域網(wǎng)(Wireless Local Area Network)的縮寫,意味著它是一種在有限范圍內(nèi)使用無線技術(shù)進(jìn)行數(shù)據(jù)傳輸?shù)?b class='flag-5'>局域網(wǎng)。相比有線
    發(fā)表于 06-14 17:18 ?3999次閱讀

    ESP32ESP32通過Internet進(jìn)行通信

    電子發(fā)燒友網(wǎng)站提供《ESP32ESP32通過Internet進(jìn)行通信.zip》資料免費(fèi)下載
    發(fā)表于 06-15 09:58 ?5次下載
    <b class='flag-5'>ESP32</b>到<b class='flag-5'>ESP32</b><b class='flag-5'>通過</b>Internet進(jìn)行通信