{"id":164560,"date":"2024-12-19T14:04:20","date_gmt":"2024-12-19T14:04:20","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=164560"},"modified":"2024-12-20T15:42:22","modified_gmt":"2024-12-20T15:42:22","slug":"esp8266-nodemcu-ota-elegantota-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-ota-elegantota-arduino\/","title":{"rendered":"ESP8266 NodeMCU OTA (Over-the-Air) Updates \u2013  ElegantOTA Library with Arduino IDE"},"content":{"rendered":"\n<p>This tutorial shows how to do OTA (over-the-air) updates to your ESP8266 NodeMCU boards using the ElegantOTA library (V3 version) with Arduino IDE. This library sets up a web server that lets you update the firmware (a new sketch) on your board wirelessly. This way, you don&#8217;t need a connection between the ESP8266 and your computer to upload a new sketch.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-ElegantOTA-Arduino-IDE.jpg?resize=1024%2C576&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU OTA (Over-the-Air) Updates \u2013 ElegantOTA Library with Arduino IDE\" class=\"wp-image-164587\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-ElegantOTA-Arduino-IDE.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-ElegantOTA-Arduino-IDE.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-ElegantOTA-Arduino-IDE.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-ElegantOTA-Arduino-IDE.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-ElegantOTA-Arduino-IDE.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>By the end of this tutorial, you\u2019ll be able to easily add OTA capabilities to your web server projects with the ESP8266 to upload new firmware wirelessly in the future.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Table Of Contents<\/h2>\n\n\n\n<p>Throughout this tutorial, we&#8217;ll cover:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#elegant-ota-usage\" title=\"\">Add the ElegantOTA feature to your web server<\/a><\/li>\n\n\n\n<li><a href=\"#upload-new-firmware-ota\" title=\"\">Upload new firmware via OTA to the ESP8266 board<\/a><\/li>\n<\/ul>\n\n\n\n<p>We recommend that you follow all the tutorial steps to understand how the <a href=\"https:\/\/github.com\/ayushsharma82\/ElegantOTA\" target=\"_blank\" rel=\"noopener\" title=\"\">ElegantOTA library<\/a> works and how you can use it in your projects. To demonstrate how to do this, we\u2019ll upload files to build different web server projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ESP8266 OTA (Over-the-Air) Programming<\/h2>\n\n\n\n<p>OTA (Over-the-Air) update is the process of loading new firmware to the ESP8266 board using a Wi-Fi connection rather than a serial communication. This functionality is extremely useful in case of no physical access to the ESP8266 board. You don&#8217;t need a connection between your computer and the board to upload new code.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"737\" height=\"371\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/01\/ESP8266-Async-ElegantOTA-How-it-Works_ESP8266-ElegantOTA.png?resize=737%2C371&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Async ElegantOTA Web Server How it Works ESP8266\" class=\"wp-image-101685\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/01\/ESP8266-Async-ElegantOTA-How-it-Works_ESP8266-ElegantOTA.png?w=737&amp;quality=100&amp;strip=all&amp;ssl=1 737w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/01\/ESP8266-Async-ElegantOTA-How-it-Works_ESP8266-ElegantOTA.png?resize=300%2C151&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/figure><\/div>\n\n\n<p>There are different ways to perform OTA updates. In this tutorial, we\u2019ll cover how to do that using the <a href=\"https:\/\/github.com\/ayushsharma82\/ElegantOTA\" target=\"_blank\" rel=\"noopener\" title=\"\">ElegantOTA library<\/a> (version V3 \u2014 this is the successor of the deprecated <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-ota-over-the-air-arduino\/\" title=\"\">AsyncElegantOTA library<\/a>). In our opinion, this is one of the best and easiest ways to perform OTA updates.<\/p>\n\n\n\n<p>The ElegantOTA library creates a web server that you can access on your local network to upload new firmware or files to the filesystem (SPIFFS or LittleFS). The files you upload should be in <em>.bin<\/em> format. We\u2019ll show you later in this tutorial how to convert your files to <em>.bin<\/em> format.<\/p>\n\n\n\n<p>The only disadvantage of OTA programming is that you need to add the code for OTA in every sketch you upload so that you\u2019re able to use OTA in the future. In case of the ElegantOTA library, it consists of just three lines of code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"elegant-ota-usage\">ElegantOTA Library<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"796\" height=\"190\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/elegantota-logo.png?resize=796%2C190&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ElegantOTA logo\" class=\"wp-image-164532\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/elegantota-logo.png?w=796&amp;quality=100&amp;strip=all&amp;ssl=1 796w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/elegantota-logo.png?resize=300%2C72&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/elegantota-logo.png?resize=768%2C183&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 796px) 100vw, 796px\" \/><\/figure><\/div>\n\n\n<p>Here are some great features of this library:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is compatible with the built-in <span class=\"rnthl rntliteral\">ESP8266WebServer.h<\/span> library and with several forks of the <span class=\"rnthl rntliteral\">ESPAsyncWebServer<\/span> library.<\/li>\n\n\n\n<li>You just need to add three lines of code to add OTA capabilities to your \u201cregular\u201d web server;<\/li>\n\n\n\n<li>It allows you to update not only new firmware to the board but also files to the ESP8266 filesystem (LittleFS or SPIFFS);<\/li>\n\n\n\n<li>It provides a beautiful and modern web server interface;<\/li>\n\n\n\n<li>It is available as a pro paid version that adds more features.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">OTA Updates with the ElegantOTA Library &#8211; Quick Summary<\/h3>\n\n\n\n<p>To add OTA capabilities to your projects using the ElegantOTA library, follow these steps:<\/p>\n\n\n\n<p><strong>1) <\/strong>Install the <a href=\"https:\/\/github.com\/ayushsharma82\/ElegantOTA\" target=\"_blank\" rel=\"noopener\" title=\"\">ElegantOTA<\/a>, <a href=\"https:\/\/github.com\/me-no-dev\/ESPAsyncTCP\" target=\"_blank\" rel=\"noopener\" title=\"\">ESPAsyncTCP<\/a>, and <a href=\"https:\/\/github.com\/me-no-dev\/ESPAsyncWebServer\" target=\"_blank\" rel=\"noreferrer noopener\">ESPAsyncWebServer <\/a>libraries;<\/p>\n\n\n\n<p><strong>2)<\/strong> Include ElegantOTA library at the top of the Arduino sketch:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code><span class=\"rnthl rntliteral\">#include &lt;ElegantOTA.h&gt;;<\/span><\/code><\/pre>\n\n\n\n<p><strong>3)<\/strong> Add the following line in the setup before <span class=\"rnthl rntliteral\">server.begin();<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ElegantOTA.begin(&amp;server);<\/code><\/pre>\n\n\n\n<p><strong>4)<\/strong> In the <span class=\"rnthl rntliteral\">loop()<\/span>, add the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ElegantOTA.loop();<\/code><\/pre>\n\n\n\n<p><strong>5)<\/strong> Open your browser and go to <span class=\"rnthl rntliteral\">http:\/\/&lt;IPAddress&gt;\/update<\/span>, where <span class=\"rnthl rntliteral\">&lt;IPAddress&gt;<\/span> is your ESP8266 IP address to access the web server page for the OTA updates.<\/p>\n\n\n\n<p>Continue reading the tutorial for more detailed steps.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How does OTA Web Updater Work?<\/h3>\n\n\n\n<p>The first sketch must be uploaded using a serial connection. This sketch should include the code to set up the OTA Web Updater, allowing you to upload new sketches through a web browser.<\/p>\n\n\n\n<p>The OTA Web Updater creates a web server where you can upload sketches wirelessly.<\/p>\n\n\n\n<p>If your code doesn\u2019t include an OTA routine, you won\u2019t be able to use the web server to upload new sketches wirelessly.<\/p>\n\n\n\n<p>After that, make sure every sketch you upload includes OTA routines so you can continue updating the board wirelessly in the future.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing the ElegantOTA Library<\/h2>\n\n\n\n<p>To install the ElegantOTA library in the Arduino IDE go to <strong>Sketch <\/strong>&gt; <strong>Include Library<\/strong> &gt; <strong>Manage Libraries<\/strong>, search for <strong>ElegantOTA <\/strong>and install the <em>ElegantOTA library by Ayush Sharma<\/em>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"586\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/install-elegantota-library-Arduino-IDE.png?resize=877%2C586&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing ElegantOTA Library Arduino IDE\" class=\"wp-image-164503\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/install-elegantota-library-Arduino-IDE.png?w=877&amp;quality=100&amp;strip=all&amp;ssl=1 877w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/install-elegantota-library-Arduino-IDE.png?resize=300%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/install-elegantota-library-Arduino-IDE.png?resize=768%2C513&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 877px) 100vw, 877px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Enabling Async Mode<\/h3>\n\n\n\n<p>For the ElegantOTA library to work in async mode (with the ESPAsyncWebServer library), you need to do the following procedure.<\/p>\n\n\n\n<p><strong>1)<\/strong> Go to your Arduino <em>libraries <\/em>directory.<\/p>\n\n\n\n<p><strong>2)<\/strong> Open the <em>ElegantOTA<\/em> folder and then open the <em>src <\/em>folder.<\/p>\n\n\n\n<p><strong>3)<\/strong> Locate the <span class=\"rnthl rntliteral\">ELEGANTOTA_USE_ASYNC_WEBSERVER<\/span> macro in the <em>ElegantOTA.h<\/em> file, and set it to <span class=\"rnthl rntliteral\">1<\/span> as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define ELEGANTOTA_USE_ASYNC_WEBSERVER 1<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"711\" height=\"357\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/elegant-ota-set-async-mode.png?resize=711%2C357&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"elegantota library enable async mode\" class=\"wp-image-164505\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/elegant-ota-set-async-mode.png?w=711&amp;quality=100&amp;strip=all&amp;ssl=1 711w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/elegant-ota-set-async-mode.png?resize=300%2C151&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/figure><\/div>\n\n\n<p><strong>4)<\/strong> Save the changes to the <em>ElegantOTA.h<\/em> file.<\/p>\n\n\n\n<p><strong>5)<\/strong> Now you can use the ElegantOTA in async mode for your OTA updates and with the  ESPAsyncWebServer library.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install ESPAsyncTCP and ESPAsyncWebServer Libraries<\/h3>\n\n\n\n<p>To test the examples in this tutorial, you also need to install the ESPAsyncTCP and the ESPAsyncWebServer libraries.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\"><strong>Note:<\/strong> the ElegantOTA library works with different forked versions of the ESPAsyncWebServer and the ESPAsyncTCP web server libraries, so you don&#8217;t necessarily need to use the same ones that we&#8217;re using.<\/p>\n\n\n\n<p>Follow the next instructions to install those libraries. <\/p>\n\n\n\n<p>Click the links below to download the libraries&#8217;<em> .zip<\/em> folders.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/me-no-dev\/ESPAsyncWebServer\/archive\/master.zip\" target=\"_blank\" rel=\"noreferrer noopener\">ESPAsyncWebServer<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/me-no-dev\/ESPAsyncTCP\/archive\/refs\/heads\/master.zip\" target=\"_blank\" rel=\"noopener\" title=\"\">ESPAsyncTCP<\/a><\/li>\n<\/ul>\n\n\n\n<p>These libraries aren\u2019t available to install through the Arduino Library Manager, so you need to copy the library <em>.zip<\/em> files to the Arduino Installation <em>Libraries <\/em>folder. Alternatively, in your Arduino IDE, you can go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Add .zip Library<\/strong>&nbsp;and select the libraries you\u2019ve just downloaded.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-basic-elegantota\">ElegantOTA ESP8266 Basic Example<\/h2>\n\n\n\n<p>Let\u2019s start with a basic example (based on one of the library&#8217;s examples). The following code creates a simple web server with the ESP32. The root URL displays some text, and the&nbsp;<strong>\/update<\/strong>&nbsp;URL displays the interface to update the firmware and the filesystem.<\/p>\n\n\n\n<p>Copy the following code to your Arduino IDE.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-ota-elegantota-arduino\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Softwar\n*********\/\n\n#include &lt;Arduino.h&gt;\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESPAsyncTCP.h&gt;\n#include &lt;ESPAsyncWebServer.h&gt;\n#include &lt;ElegantOTA.h&gt;\n\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\nAsyncWebServer server(80);\n\nvoid setup(void) {\n  Serial.begin(115200);\n  WiFi.mode(WIFI_STA);\n  WiFi.begin(ssid, password);\n  Serial.println(&quot;&quot;);\n\n  \/\/ Wait for connection\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println(&quot;&quot;);\n  Serial.print(&quot;Connected to &quot;);\n  Serial.println(ssid);\n  Serial.print(&quot;IP address: &quot;);\n  Serial.println(WiFi.localIP());\n\n  server.on(&quot;\/&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {\n    request-&gt;send(200, &quot;text\/plain&quot;, &quot;Hi! I am ESP8266.&quot;);\n  });\n\n  server.begin();\n  Serial.println(&quot;HTTP server started&quot;);\n\n  ElegantOTA.begin(&amp;server);    \/\/ Start ElegantOTA\n}\n\nvoid loop(void) {\n  ElegantOTA.loop();\n\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ElegantOTA\/ESP8266_ElegantOTA_Basic.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Insert your network credentials and the code should work straight away.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How Does the Code Work?<\/h3>\n\n\n\n<p>Start by including the required libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Arduino.h&gt;\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESPAsyncTCP.h&gt;\n#include &lt;ESPAsyncWebServer.h&gt;\n#include &lt;ElegantOTA.h&gt;<\/code><\/pre>\n\n\n\n<p>Insert your network credentials in the following variables so that the ESP32 can connect to the Wi-Fi on your local network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>Create an <span class=\"rnthl rntliteral\">AsyncWebServer<\/span> object on port 80:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>AsyncWebServer server(80);<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Initialize Wi-Fi:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFi.mode(WIFI_STA);\nWiFi.begin(ssid, password);\nSerial.println(\"\");\n\n\/\/ Wait for connection\nwhile (WiFi.status() != WL_CONNECTED) {\n  delay(500);\n  Serial.print(\".\");\n}\nSerial.println(\"\");\nSerial.print(\"Connected to \");\nSerial.println(ssid);\nSerial.print(\"IP address: \");\nSerial.println(WiFi.localIP());<\/code><\/pre>\n\n\n\n<p>Then, handle the client requests. The following lines, send some text <span class=\"rnthl rntliteral\">Hi! I am ESP8266<\/span> when you access the root (<span class=\"rnthl rntliteral\">\/<\/span>) URL:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.on(\"\/\", HTTP_GET, &#091;](AsyncWebServerRequest *request) {\n  request-&gt;send(200, \"text\/plain\", \"Hi! I am ESP8266.\");\n});<\/code><\/pre>\n\n\n\n<p>If your web server needs to handle more requests you can add them (we&#8217;ll show you in the next example).<\/p>\n\n\n\n<p>Initialize the server:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>server.begin();<\/code><\/pre>\n\n\n\n<p>Then, add the next line to start ElegantOTA:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ElegantOTA.begin(&amp;server);    \/\/ Start ElegantOTA<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, add the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ElegantOTA.loop();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing the Web Server<\/h2>\n\n\n\n<p>After uploading code to the board, open the Serial Monitor at a baud rate of 115200. Press the ESP8266 on-board RST button. It should display the ESP IP address as follows (yours may be different):<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"320\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-ip-address.png?resize=723%2C320&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 ElegantOTA Web Server Getting the IP Address Serial Monitor\" class=\"wp-image-164562\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-ip-address.png?w=723&amp;quality=100&amp;strip=all&amp;ssl=1 723w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-ip-address.png?resize=300%2C133&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/figure><\/div>\n\n\n<p>In your local network, open your browser and type the ESP8266 IP address. You should get access the root (<span class=\"rnthl rntliteral\">\/<\/span>) web page with some text displayed.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"587\" height=\"315\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-web-server-basic-with-ota.png?resize=587%2C315&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU Web Server Basic OTA \" class=\"wp-image-164563\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-web-server-basic-with-ota.png?w=587&amp;quality=100&amp;strip=all&amp;ssl=1 587w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-web-server-basic-with-ota.png?resize=300%2C161&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/figure><\/div>\n\n\n<p>Now, if you want to modify your web server code via OTA, go to the ESP IP address followed by <span class=\"rnthl rntliteral\">\/update<\/span>. The following web page should load.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"941\" height=\"665\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-ota-web-server.png?resize=941%2C665&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ElegantOTA Web Server Page ESP8266\" class=\"wp-image-164564\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-ota-web-server.png?w=941&amp;quality=100&amp;strip=all&amp;ssl=1 941w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-ota-web-server.png?resize=300%2C212&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/esp8266-ota-web-server.png?resize=768%2C543&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/figure><\/div>\n\n\n<p>To upload new code to your board or files to the filesystem, you need to upload them in <em>.bin<\/em> format. Follow the next section to learn how to generate a <em>.bin<\/em> file from your sketch in Arduino IDE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"upload-new-firmware-ota\">Upload New Code to the ESP8266 via OTA<\/h2>\n\n\n\n<p>Every file that you upload via OTA should be in&nbsp;<em>.bin<\/em>&nbsp;format. You can generate a&nbsp;<em>.bin<\/em>&nbsp;file from your sketch using the Arduino IDE.<\/p>\n\n\n\n<p>With your sketch opened, you just need to select the ESP8266 board you&#8217;re using in <strong>Tools<\/strong> &gt; <strong>Board<\/strong>, and then go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Export Compiled Binary<\/strong>. A&nbsp;<em>.bin<\/em>&nbsp;file will be generated from your sketch.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"383\" height=\"272\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/export-bin-file-arduino-ide.jpg?resize=383%2C272&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino IDE, expor bin file\" class=\"wp-image-164549\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/export-bin-file-arduino-ide.jpg?w=383&amp;quality=100&amp;strip=all&amp;ssl=1 383w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/export-bin-file-arduino-ide.jpg?resize=300%2C213&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 383px) 100vw, 383px\" \/><\/figure><\/div>\n\n\n<p>The generated file will be saved under your project folder inside a series of other folders. The file with the <em>.ino.bin<\/em>&nbsp;extension is the one you should upload to your board using the ElegantOTA web page.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Upload a New Web Server Sketch via OTA &#8211; Example<\/h3>\n\n\n\n<p>Imagine that after uploading the previous sketch, you want to upload a new one that allows you to control an LED via a web interface like <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-websocket-server-arduino\/\" title=\"\">this project<\/a>. Here are the steps you need to follow:<\/p>\n\n\n\n<p>1. Copy the following code to your Arduino IDE. Don&#8217;t forget to insert your network credentials.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-ota-elegantota-arduino\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Softwar\n*********\/\n\n\/\/ Import required libraries\n#include &lt;Arduino.h&gt;\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESPAsyncTCP.h&gt;\n#include &lt;ESPAsyncWebServer.h&gt;\n#include &lt;ElegantOTA.h&gt;\n\n\/\/ Replace with your network credentials\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\nbool ledState = 0;\nconst int ledPin = 2;\n\n\/\/ Create AsyncWebServer object on port 80\nAsyncWebServer server(80);\nAsyncWebSocket ws(&quot;\/ws&quot;);\n\nconst char index_html[] PROGMEM = R&quot;rawliteral(\n&lt;!DOCTYPE HTML&gt;&lt;html&gt;\n&lt;head&gt;\n  &lt;title&gt;ESP Web Server&lt;\/title&gt;\n  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;\n  &lt;link rel=&quot;icon&quot; href=&quot;data:,&quot;&gt;\n  &lt;style&gt;\n  html {\n    font-family: Arial, Helvetica, sans-serif;\n    text-align: center;\n  }\n  h1 {\n    font-size: 1.8rem;\n    color: white;\n  }\n  h2{\n    font-size: 1.5rem;\n    font-weight: bold;\n    color: #143642;\n  }\n  .topnav {\n    overflow: hidden;\n    background-color: #143642;\n  }\n  body {\n    margin: 0;\n  }\n  .content {\n    padding: 30px;\n    max-width: 600px;\n    margin: 0 auto;\n  }\n  .card {\n    background-color: #F8F7F9;;\n    box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5);\n    padding-top:10px;\n    padding-bottom:20px;\n  }\n  .button {\n    padding: 15px 50px;\n    font-size: 24px;\n    text-align: center;\n    outline: none;\n    color: #fff;\n    background-color: #0f8b8d;\n    border: none;\n    border-radius: 5px;\n    -webkit-touch-callout: none;\n    -webkit-user-select: none;\n    -khtml-user-select: none;\n    -moz-user-select: none;\n    -ms-user-select: none;\n    user-select: none;\n    -webkit-tap-highlight-color: rgba(0,0,0,0);\n   }\n   \/*.button:hover {background-color: #0f8b8d}*\/\n   .button:active {\n     background-color: #0f8b8d;\n     box-shadow: 2 2px #CDCDCD;\n     transform: translateY(2px);\n   }\n   .state {\n     font-size: 1.5rem;\n     color:#8c8c8c;\n     font-weight: bold;\n   }\n  &lt;\/style&gt;\n&lt;title&gt;ESP Web Server&lt;\/title&gt;\n&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;\n&lt;link rel=&quot;icon&quot; href=&quot;data:,&quot;&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=&quot;topnav&quot;&gt;\n    &lt;h1&gt;ESP WebSocket Server&lt;\/h1&gt;\n  &lt;\/div&gt;\n  &lt;div class=&quot;content&quot;&gt;\n    &lt;div class=&quot;card&quot;&gt;\n      &lt;h2&gt;Output - GPIO 2&lt;\/h2&gt;\n      &lt;p class=&quot;state&quot;&gt;state: &lt;span id=&quot;state&quot;&gt;%STATE%&lt;\/span&gt;&lt;\/p&gt;\n      &lt;p&gt;&lt;button id=&quot;button&quot; class=&quot;button&quot;&gt;Toggle&lt;\/button&gt;&lt;\/p&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;script&gt;\n  var gateway = `ws:\/\/${window.location.hostname}\/ws`;\n  var websocket;\n  window.addEventListener('load', onLoad);\n  function initWebSocket() {\n    console.log('Trying to open a WebSocket connection...');\n    websocket = new WebSocket(gateway);\n    websocket.onopen    = onOpen;\n    websocket.onclose   = onClose;\n    websocket.onmessage = onMessage; \/\/ &lt;-- add this line\n  }\n  function onOpen(event) {\n    console.log('Connection opened');\n  }\n  function onClose(event) {\n    console.log('Connection closed');\n    setTimeout(initWebSocket, 2000);\n  }\n  function onMessage(event) {\n    var state;\n    if (event.data == &quot;1&quot;){\n      state = &quot;ON&quot;;\n    }\n    else{\n      state = &quot;OFF&quot;;\n    }\n    document.getElementById('state').innerHTML = state;\n  }\n  function onLoad(event) {\n    initWebSocket();\n    initButton();\n  }\n  function initButton() {\n    document.getElementById('button').addEventListener('click', toggle);\n  }\n  function toggle(){\n    websocket.send('toggle');\n  }\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;)rawliteral&quot;;\n\nvoid notifyClients() {\n  ws.textAll(String(ledState));\n}\n\nvoid handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {\n  AwsFrameInfo *info = (AwsFrameInfo*)arg;\n  if (info-&gt;final &amp;&amp; info-&gt;index == 0 &amp;&amp; info-&gt;len == len &amp;&amp; info-&gt;opcode == WS_TEXT) {\n    data[len] = 0;\n    if (strcmp((char*)data, &quot;toggle&quot;) == 0) {\n      ledState = !ledState;\n      notifyClients();\n    }\n  }\n}\n\nvoid onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type,\n             void *arg, uint8_t *data, size_t len) {\n  switch (type) {\n    case WS_EVT_CONNECT:\n      Serial.printf(&quot;WebSocket client #%u connected from %s\\n&quot;, client-&gt;id(), client-&gt;remoteIP().toString().c_str());\n      break;\n    case WS_EVT_DISCONNECT:\n      Serial.printf(&quot;WebSocket client #%u disconnected\\n&quot;, client-&gt;id());\n      break;\n    case WS_EVT_DATA:\n      handleWebSocketMessage(arg, data, len);\n      break;\n    case WS_EVT_PONG:\n    case WS_EVT_ERROR:\n      break;\n  }\n}\n\nvoid initWebSocket() {\n  ws.onEvent(onEvent);\n  server.addHandler(&amp;ws);\n}\n\nString processor(const String&amp; var){\n  Serial.println(var);\n  if(var == &quot;STATE&quot;){\n    if (ledState){\n      return &quot;ON&quot;;\n    }\n    else{\n      return &quot;OFF&quot;;\n    }\n  }\n  return String();\n}\n\nvoid setup(){\n  \/\/ Serial port for debugging purposes\n  Serial.begin(115200);\n\n  pinMode(ledPin, OUTPUT);\n  digitalWrite(ledPin, LOW);\n  \n  \/\/ Connect to Wi-Fi\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(1000);\n    Serial.println(&quot;Connecting to WiFi..&quot;);\n  }\n\n  \/\/ Print ESP Local IP Address\n  Serial.println(WiFi.localIP());\n\n  initWebSocket();\n\n  \/\/ Route for root \/ web page\n  server.on(&quot;\/&quot;, HTTP_GET, [](AsyncWebServerRequest *request){\n    request-&gt;send(200, &quot;text\/html&quot;, index_html, processor);\n  });\n\n  \/\/ Start server\n  server.begin();\n  ElegantOTA.begin(&amp;server);    \/\/ Start ElegantOTA\n}\n\nvoid loop() {\n  ws.cleanupClients();\n  digitalWrite(ledPin, !ledState);\n  ElegantOTA.loop();\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ElegantOTA\/ESP8266_WebServer_LED_ElegantOTA.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>This is the same code used in<a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-websocket-server-arduino\/\" title=\"\"> this project<\/a>, but it contains the needed lines of code to handle ElegantOTA:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;ElegantOTA.h&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ElegantOTA.begin(&amp;server);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ElegantOTA.loop();<\/code><\/pre>\n\n\n\n<p><strong>2. <\/strong>Save your sketch: <strong>File<\/strong> &gt; <strong>Save <\/strong>and give it a name. For example: <em>ESP8266_WebServer_LED_OTA<\/em>.<\/p>\n\n\n\n<p><strong>3.<\/strong> Generate a <em>.bin<\/em> file from your sketch. First, select the board model you&#8217;re using in <strong>Tools<\/strong> &gt; <strong>Board<\/strong>. Then, go to <strong>Sketch <\/strong>&gt; <strong>Export Compiled Binary<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"383\" height=\"272\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/export-bin-file-arduino-ide.jpg?resize=383%2C272&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino IDE, export bin file\" class=\"wp-image-164549\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/export-bin-file-arduino-ide.jpg?w=383&amp;quality=100&amp;strip=all&amp;ssl=1 383w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/export-bin-file-arduino-ide.jpg?resize=300%2C213&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 383px) 100vw, 383px\" \/><\/figure><\/div>\n\n\n<p>Go to your sketch folder. You should have a <em>build<\/em> folder. Inside that folder, you&#8217;ll have another folder related to your board model. Open that folder. There&#8217;ll be several files. You should upload the file with the <em>ino.bin<\/em> extension.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"673\" height=\"264\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-bin-file-from-sketch.png?resize=673%2C264&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"bin file for ESP8266 OTA updates\" class=\"wp-image-164565\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-bin-file-from-sketch.png?w=673&amp;quality=100&amp;strip=all&amp;ssl=1 673w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-bin-file-from-sketch.png?resize=300%2C118&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/figure><\/div>\n\n\n<p><strong>4.<\/strong> Now, you need to upload that file using the ElegantOTA page. Go to your ESP IP address followed by <span class=\"rnthl rntliteral\">\/update<\/span>. Make sure you have the <strong>firmware<\/strong> option selected. Click on <strong>Choose File<\/strong> and select the <em>.ino.bin<\/em> file you&#8217;ve just generated.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"857\" height=\"664\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-upload-new-firmware-OTA.png?resize=857%2C664&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 ElegantOTA Uploading new firmware\" class=\"wp-image-164566\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-upload-new-firmware-OTA.png?w=857&amp;quality=100&amp;strip=all&amp;ssl=1 857w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-upload-new-firmware-OTA.png?resize=300%2C232&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-upload-new-firmware-OTA.png?resize=768%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/figure><\/div>\n\n\n<p><strong>5.<\/strong> After a few seconds, you should get a success message. Then, click on the <strong>Back<\/strong> button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"528\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-OTA_upload-success.png?resize=721%2C528&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 ElegantOTA Upload new Firmware Success\" class=\"wp-image-164567\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-OTA_upload-success.png?w=721&amp;quality=100&amp;strip=all&amp;ssl=1 721w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-OTA_upload-success.png?resize=300%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/figure><\/div>\n\n\n<p><strong>6. <\/strong>Now, you can go to the root (<span class=\"rnthl rntliteral\">\/<\/span>) URL to access the new web server. This is the page you should see when you access the ESP IP address on the root (<span class=\"rnthl rntliteral\">\/<\/span>) URL.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"823\" height=\"536\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-control-gpio-websocket-server.png?resize=823%2C536&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Websocket server - control outputs\" class=\"wp-image-164568\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-control-gpio-websocket-server.png?w=823&amp;quality=100&amp;strip=all&amp;ssl=1 823w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-control-gpio-websocket-server.png?resize=300%2C195&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-control-gpio-websocket-server.png?resize=768%2C500&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 823px) 100vw, 823px\" \/><\/figure><\/div>\n\n\n<p>You can click on the button to turn the ESP8266 on-board LED on and off.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP8266-NodeMCU-kit-12-E-on-board-LED.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU onboard LED on\" class=\"wp-image-84975\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP8266-NodeMCU-kit-12-E-on-board-LED.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/ESP8266-NodeMCU-kit-12-E-on-board-LED.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Because we&#8217;ve also added OTA capabilities to this new web server, we can upload a new sketch in the future if needed. You just need to go to the ESP8266 IP address followed by <span class=\"rnthl rntliteral\">\/update<\/span>.<\/p>\n\n\n\n<p>Congratulations, you&#8217;ve uploaded new code to your ESP8266 via Wi-Fi using ElegantOTA.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial you&#8217;ve learned how to add OTA capabilities to your Async Web Server projects using the ElegantOTA library on the ESP8266 board. This library is straightforward to use\u2014you just need to add three lines of code to your project.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful.<\/p>\n\n\n\n<p>Learn more about the ESP8266 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\" title=\"\">Home Automation Using ESP8266<\/a> (eBook)<\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build ESP32 Web Servers with Arduino IDE<\/a> (eBook)<\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\" title=\"\">More ESP8266 Projects and Tutorials&#8230; <\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to do OTA (over-the-air) updates to your ESP8266 NodeMCU boards using the ElegantOTA library (V3 version) with Arduino IDE. This library sets up a web server &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP8266 NodeMCU OTA (Over-the-Air) Updates \u2013  ElegantOTA Library with Arduino IDE\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-ota-elegantota-arduino\/#more-164560\" aria-label=\"Read more about ESP8266 NodeMCU OTA (Over-the-Air) Updates \u2013  ElegantOTA Library with Arduino IDE\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":164587,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[265,214,246,300,240,264],"tags":[],"class_list":["post-164560","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-project","category-esp8266","category-esp8266-arduino-ide","category-0-esp8266","category-esp8266-projects","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/12\/ESP8266-ElegantOTA-Arduino-IDE.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/164560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=164560"}],"version-history":[{"count":6,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/164560\/revisions"}],"predecessor-version":[{"id":164858,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/164560\/revisions\/164858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/164587"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=164560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=164560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=164560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}