本站改版新增arduino频道
arduino ESP32httpUpdate库 OTA(Over-The-Air)更新
#include #include #include // 设置WiFi信息 const char* ssid = "xxxxx"; const char* password = "xxxxx"; // 固件更新 URL const char* update_url = "https://xxx.xxx.com/Blink.ino.bin"; void setup() { // 初始化串口 Serial.begin(115200); // 连接WiFi WiFi.begin(ssid, password); Serial.print("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected to the WiFi network"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); // 检查更新并应用 checkForUpdates(); } void loop() { // 在这里添加你的代码 } void checkForUpdates() { Serial.println("Checking for firmware updates..."); t_httpUpdate_return ret = ESPhttpUpdate.update(update_url); switch (ret) { case HTTP_UPDATE_FAILED: Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); break; case HTTP_UPDATE_NO_UPDATES: Serial.println("HTTP_UPDATE_NO_UPDATES"); break; case HTTP_UPDATE_OK: Serial.println("HTTP_UPDATE_OK"); break; } }
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0095090866088867 seconds