{"id":1331,"date":"2024-01-29T00:13:19","date_gmt":"2024-01-28T16:13:19","guid":{"rendered":"http:\/\/www.forillusion.com\/?p=1331"},"modified":"2025-02-14T11:39:10","modified_gmt":"2025-02-14T03:39:10","slug":"esp8266-ota","status":"publish","type":"post","link":"https:\/\/www.forillusion.com\/index.php\/esp8266-ota\/","title":{"rendered":"ESP8266 OTA"},"content":{"rendered":"\n<p><div class=\"has-toc have-toc\"><\/div><\/p>\n\n\n\n<p>ESP8266\u7684OTA\u5347\u7ea7\u6709\u4e24\u79cd\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u5229\u7528ArduinoOTA\u5e93\uff0c\u53e6\u4e00\u79cd\u662f\u901a\u8fc7ESP8266HTTPUpdateServer\u5e93\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ArduinoOTA\u5e93<\/h2>\n\n\n\n<p>\u4f7f\u7528ArduinoOTA\u5e93\u53ef\u4ee5\u5728Arduino IDE\u5185\u76f4\u63a5\u8fdb\u884c\u8fdc\u7a0b\u66f4\u65b0\u3002\u4f18\u52bf\u7684\u4ee3\u7801\u7b80\u6d01\uff0c\u64cd\u4f5c\u65b9\u4fbf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;ArduinoOTA.h>   \/\/\u5934\u6587\u4ef6\n\n\/\/setup:\nArduinoOTA.setHostname(\"ESP8266\");\r   \/\/\u8bbe\u7f6e\u4e0a\u4f20\u540d\u79f0\nArduinoOTA.setPassword(\"12345678\");  \/\/\u8bbe\u7f6e\u4e0a\u4f20\u5bc6\u7801\uff0c\u8fd9\u4e24\u9879\u53ef\u4ee5\u4e0d\u5199\u3002\nArduinoOTA.begin();   \/\/\u542f\u52a8OTA\n\n\/\/loop:\nArduinoOTA.handle();   \/\/\u6301\u7eed\u67e5\u770b\u662f\u5426\u6709\u66f4\u65b0\u8bf7\u6c42<\/code><\/pre>\n\n\n\n<p>\u5728IDE\u4e2d\u9009\u62e9\uff1a\u5de5\u5177->\u7aef\u53e3->\u7f51\u7edc\u7aef\u53e3<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"192\" height=\"145\"   class=\"lazyload\" data-src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-3.png\" src=\"https:\/\/cdn.forillusion.com\/moezx\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" class=\"wp-image-1333\"\/><\/figure >\n<noscript><img loading=\"lazy\" decoding=\"async\" width=\"192\" height=\"145\" src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-3.png\" alt=\"\" class=\"wp-image-1333\"\/><\/figure><\/noscript>\n\n\n\n<h2 class=\"wp-block-heading\">ESP8266HTTPUpdateServer\u5e93<\/h2>\n\n\n\n<p>\u8be5\u65b9\u6cd5\u8f83\u4e3a\u9ebb\u70e6\uff0c\u901a\u8fc7\u670d\u52a1\u5668\u548c\u7f51\u9875\u8fdb\u884c\u4e0a\u4f20\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;ESP8266WiFi.h> \r  \/\/\u5934\u6587\u4ef6\n#include &lt;WiFiClient.h>   \r\n#include &lt;ESP8266WebServer.h>\r\n#include &lt;ESP8266HTTPUpdateServer.h>\n\nESP8266WebServer httpServer(80);\r   \/\/\u5b9a\u4e49\u670d\u52a1\u5668\nESP8266HTTPUpdateServer httpUpdater;\n\n\/\/setup:\n\/\/\u9700\u8981\u5148\u8fde\u63a5WiFi\nhttpUpdater.setup(&amp;httpServer); \nhttpServer.begin();   \/\/\u5f00\u542f\u8ddf\u65b0\u670d\u52a1\n\nSerial.print(\"HTTPUpdateServer ready! Open http:\/\/\");\r   \/\/\u6253\u5370\u7f51\u9875\u5730\u5740\nSerial.print(WiFi.localIP());\r\nSerial.println(\"\/update in your browser\");\n\n\/\/loop:\nhttpServer.handleClient();   \/\/\u6301\u7eed\u67e5\u770b\u662f\u5426\u6709\u66f4\u65b0\u8bf7\u6c42<\/code><\/pre>\n\n\n\n<p>ESP8266\u4f1a\u901a\u8fc7\u4e32\u53e3\u6253\u5370OTA\u66f4\u65b0\u7684\u5730\u5740<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"593\" height=\"50\"   class=\"lazyload\" data-src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-5.png\" src=\"https:\/\/cdn.forillusion.com\/moezx\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" class=\"wp-image-1335\" srcset=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-5.png 593w, https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-5-300x25.png 300w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/figure >\n<noscript><img loading=\"lazy\" decoding=\"async\" width=\"593\" height=\"50\" src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-5.png\" alt=\"\" class=\"wp-image-1335\" srcset=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-5.png 593w, https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-5-300x25.png 300w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/figure><\/noscript>\n\n\n\n<p>\u8bbf\u95ee\u8be5\u7f51\u7ad9\uff0c\u968f\u540e\u53ef\u4ee5\u770b\u5230\u4e0b\u8ff0\u5185\u5bb9<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"410\" height=\"105\"   class=\"lazyload\" data-src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-4.png\" src=\"https:\/\/cdn.forillusion.com\/moezx\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" class=\"wp-image-1334\" srcset=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-4.png 410w, https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-4-300x77.png 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/figure >\n<noscript><img loading=\"lazy\" decoding=\"async\" width=\"410\" height=\"105\" src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-4.png\" alt=\"\" class=\"wp-image-1334\" srcset=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-4.png 410w, https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/01\/image-4-300x77.png 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/figure><\/noscript>\n\n\n\n<p>\u7136\u540e\u9009\u62e9\u5bf9\u5e94\u7684\u6587\u4ef6\uff0cFirmware\u662f\u66f4\u65b0\u7a0b\u5e8f\uff0cFileSystem\u662f\u66f4\u65b0\u6587\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;ESP8266WiFi.h> \r\n#include &lt;ArduinoOTA.h>  \/\/ OTA\u5e93\r\n#include &lt;WiFiClient.h>   \r\n#include &lt;ESP8266WebServer.h>\r\n#include &lt;ESP8266HTTPUpdateServer.h>\r\n\nconst char *ssid = \"ssid\";\r\nconst char *password = \"password\";\r\n\nESP8266WebServer httpServer(80);\r\nESP8266HTTPUpdateServer httpUpdater;\r\n\r\nint l=0,t=0;\r\n\r\nvoid setup(void)\r\n{\r\n    pinMode(LED_BUILTIN, OUTPUT);\r\n    \r\n    Serial.begin(115200);\r\n    Serial.println();\r\n    Serial.println(\"web OAT:blick v1.0\"); \/\/ \u663e\u793a\u7248\u672c\r\n    WiFi.mode(WIFI_STA);\r\n    WiFi.begin(ssid, password);\r\n\r\n    Serial.print(\"Connecting...\");\r\n    while (WiFi.status() != WL_CONNECTED)\r\n    {\r\n        Serial.print(\".\");\r\n        delay(300);\r\n    }\r\n\r\n    Serial.println();\r\n\r\n    httpUpdater.setup(&amp;httpServer); \/\/ \u7f51\u9875\u66f4\u65b0\u56fa\u4ef6\r\n    httpServer.begin();\r\n\r\n    Serial.print(\"HTTPUpdateServer ready! Open http:\/\/\");\r\n    Serial.print(WiFi.localIP());\r\n    Serial.println(\"\/update in your browser\");\r\n\n\/\/    ArduinoOTA.setHostname(\"ESP8266\");\r\n\/\/    ArduinoOTA.setPassword(\"12345678\");\r\n    ArduinoOTA.begin();\r\n}\r\n\r\nvoid loop(void)\r\n{\r\n    int now = millis();\r\n    if (now - l >2000)\r\n    {\r\n      l=now;\r\n      if (t==0) digitalWrite(LED_BUILTIN,HIGH),t=1;\r\n      else digitalWrite(LED_BUILTIN,LOW),t=0;\r\n    }\r\n    httpServer.handleClient();\r\n    ArduinoOTA.handle();\r\n    \r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ESP8266\u7684OTA\u5347\u7ea7\u6709\u4e24\u79cd\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u5229\u7528ArduinoOTA\u5e93\uff0c\u53e6\u4e00\u79cd\u662f\u901a\u8fc7ESP8266HTTPUpdateServer &#8230;<\/p>","protected":false},"author":1,"featured_media":1336,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,3],"tags":[27,26,25,12,22],"class_list":["post-1331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-38","category-3","tag-esp8266","tag-26","tag-25","tag-12","tag-22"],"_links":{"self":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/comments?post=1331"}],"version-history":[{"count":1,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1331\/revisions"}],"predecessor-version":[{"id":1736,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1331\/revisions\/1736"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media\/1336"}],"wp:attachment":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media?parent=1331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/categories?post=1331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/tags?post=1331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}