How to Update ESP32 Firmware Over -The-Air (OTA) using Arduino IDE & Web Server In the past, firmware updates in embedded systems were a critical task. But most of the IoT devices and embedded devices are connected through the internet to update the firmware remotely by developers. Devices able to connect to the Internet have the benefit of updating themselves. So this kind of firmware programming in ESP32 is referred to as OTA (Over-The-Air), which helps to keep the embedded devices up to date with minimum user intervention. Additionally, Over-The-Air offers a lot of features and is a cost-effective technique for developers to make their devices update. This article explores the OTA firmware update procedure over the ESP32 development board. What is OTA Programming in ESP32/ ESP32 OTA? ESP32 OTA is the ability to upload or update a new program into the ESP32 development board process over the internet without connecting to a computer. In addition, this process can also reduce the required time to update every ESP module in maintenance. Thus, it allows wireless updates over the Internet or other types of wireless networks. The ESP32 development board pays attention to a firmware update by downloading it using protocols like HTTPS, MQTT, or HTTP. After that, it verifies and flashes it into an allocated partition within the memory of the ESP32 board. OTA updates are significant for embedded devices or IoT devices, particularly when devices are difficult to access or in remote locations. ESP32 OTA Core Parts ESP32 OTA uses various key components for firmware updates without connecting the device physically. Thus, the core parts of this OTA help in transmitting and receiving updates. In addition, AsyncElegantOTA (or) the ESP HTTPS OTA libraries & frameworks from Espressif shorten the implementation procedure. Data Partition of OTA This partition within the ESP32 board’s flash memory simply stores the updated information of OTA, like the firmware image & a counter to track which slot was written to more recently. Communication Mechanism OTA updates mainly depend on wireless communication protocols like Bluetooth or WiFi, where Bluetooth is used for more localized and smaller updates, and WiFi is commonly used. Client-Server Architecture A client, like a mobile app or PC, initiates the update and sends the firmware to the ESP32 server. Libraries & Frameworks AsyncElegantOTA & the ESP HTTPS OTA libraries provide pre-built functionalities to handle the OTA procedure and shorten the development. Bootloader This bootloader handles the transition to the latest firmware after a successful OTA update. Safe OTA Safe OTA updates involve the firmware signature image verification to ensure its integrity & authenticity. In essence, ESP32 OTA updates involve a combination of software (partitions, libraries, and firmware) and communication protocols (Wi-Fi or Bluetooth). Thus, it seamlessly update the device’s firmware without physical access. Working ESP32 OTA programming allows the ESP32’s firmware/software to update wirelessly to a computer without a physical connection. So this can be done by sending a new firmware image over a network like Wi-Fi, and after that writing it into the flash memory of the ESP32. Thus, the ESP32 development board reboots & the latest firmware is running. Implementation of ESP32 OTA To implement Over-The-Air updates for the ESP32 development board, a basic OTA sketch must be uploaded. After that, a web server is used to upload the latest firmware. So this whole Installation of the ESP32 OTA procedure involves a Wi-Fi connection setup, library installation, and after that, a compiled binary file is uploaded into the ESP32 board. Step-by-step Procedure of ESP32 OTA Implementation: First, need to install the ESP32 board package within the Arduino IDE. After that, include the specific & other necessary libraries of ESP32. The basic OTA sketch must be uploaded, which normally contains a web server mainly for OTA updates. Open the browser and allow the web server IP address of ESP32. Choose the .bin file in the web server interface that you desire to upload. Click the upload button to start the OTA update. Now the ESP32 is connected to your Wi-Fi network. Open aard will reboot through the newly uploaded firmware. The ArduinoOTA library must be used in the ESP32 core to simplify the OTA procedure. You can also employ the BasicOTA example given by the library or make your own OTA application. Now, the ArduinoOTA library simply allows you to upload the latest sketch OTA into your ESP32. Use a Web Server In the ESP32 Arduino library, the OTAWebUpdater example provides a web interface to upload firmware. The sketch is compiled to generate a .bin file, after that it can be uploaded through the web server. This technique allows for simple and more accessible OTA updates. In addition, make sure that you have a minimum of two OTA partitions within your ESP32 board. Use other techniques like the Arduino IoT Cloud, mainly for OTA updates. The OTA procedure overwrites the existing firmware within a dedicated OTA partition by ensuring that the running firmware stays stable. ESP32 OTA Interfacing with Arduino The main feature of WiFi-enabled microcontrollers (ESP32 & ESP8266) is OTA programming. These devices upgrade their firmware wirelessly. Using OTA, an update can be sent to various microcontrollers that are on a similar network. This feature is used to send updates for resolving the bugs by including some features to several microcontrollers, set-top boxes, computers, cell phones, etc. Generally,OTA updates play a key role in the Internet of Things to update internet-connected devices remotely with new settings and software. Here we are going to use OTA programming with the ESP32 board in Arduino IDE with the OTA Web Updater. The required components for ESP32 OTA interfacing with the Arduino board include the ESP32 board and the Arduino IDE. ESP32 OTA Interfacing With Arduino OTA Code The OTA code for the ESP32 development board is given below. #include <WiFi.h> #include <WiFiClient.h> <WebServer.h> <ESPmDNS.h> <Update.h> const char* host = “esp32”; ssid = “xxx”; password = “xxxx”; 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><b>ESP32 Login Page</b></font></center>” “<br>” “</td>” “<br>” “<br>” “</tr>” “<tr>” “<td>Username:</td>” “<td><input type=’text’ size=25 name=’userid’><br></td>” “</tr>” “<br>” “<br>” “<tr>” “<td>Password:</td>” “<td><input type=’Password’ size=25 name=’pwd’><br></td>” “<br>” “<br>” “</tr>” “<tr>” “<td><input type=’submit’ onclick=’check(this.form)’ value=’Login’></td>” “</tr>” “</table>” “</form>” “<script>” “function check(form)” “{” “if(form.userid.value==’admin’ && form.pwd.value==’admin’)” “{” “window.open(‘/serverIndex’)” “}” “else” “{” ” alert(‘Error Password or Username’)/*displays error message*/” “}” “}” “</script>”; /* * Server Index Page */ const char* serverIndex = “<script src=’https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js’></script>” “<form method=’POST’ action=’#’ enctype=’multipart/form-data’ id=’upload_form’>” “<input type=’file’ name=’update’>” “<input type=’submit’ value=’Update’>” “</form>” “<div id=’prg’>progress: 0%</div>” “<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) {” “}” “});” “});” <p>”</script>”; /* * setup function */ void setup(void) { Serial.begin(115200); // Connect to the 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: %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); }}} server.begin(); } void loop(void) { server.handleClient(); delay(1); } OTA Programming Working To use the OTA programming feature, a sketch needs to be uploaded through the serial port. This sketch includes the HTML code to make an OTA Web Updater. Later, you can easily upload the code with the browser. Once the code is uploaded through a serial port, a web server will be created where you can select & upload a new sketch through a web browser. Connect the ESP32 board to the laptop to upload the primary code, then open the Arduino IDE and choose the type of board as ESP32 Dev Kit & choose the right serial port. Modify the name of the Wi-Fi & password within the original code. The OTA code must be uploaded to your ESP32 board. Once the code is successfully uploaded, open the serial monitor. After that, the baud rate of 115200 must be changed on the Serial Monitor. Press the Reset button above the ESP32 module, and it must print the IP address of the ESP32 board. Open the default browser to paste the ESP32 IP Address. So it must open the Web server page for OTA. Here username & password by default are admin. Now, enter the login details, click on the login page, and then a new tab will open to upload the code. Advantages The advantages of ESP32 OTA include the following. This centralized approach allows a single update to spread into various ESP32s on a similar network. OTA allows for upgrades of remote firmware without using physical access to the development board to make it perfect for IoT deployments. OTA removes the requirement of physical connections to update the ESP32 board by simplifying the update procedure, particularly for inaccessible or remote devices. Updates can be achieved remotely, which decreases the time spent on protection and operation. A single source sends updates to numerous ESP32s on a similar network and streamlines the update procedure for huge deployments. OTA allows simultaneous updates to several devices by making it very efficient for large-scale projects. Updates can be planned and executed in off-peak hours, which reduces trouble to the operation of the device. OTA updates include security patches & improvements that protect from vulnerabilities. OTA functionality can be integrated into ESP32-based projects with ArduinoOTA libraries. OTA programming allows you to update a new program into the ESP32 without any connection to the computer. Disadvantages The disadvantages of ESP32 OTA include the following. The factory image of the ESP32 board does not contain OTA capability. Thus, first, you need to upload this firmware through a serial connection before you use OTA updates. In addition, some older ESP32 models have memory limitations, particularly those that have 1MB of flash memory. Every uploaded sketch into an ESP32 board must contain the required code to allow OTA functionality. The device without this code will no longer be available for OTA updates through a web server. Many modern ESP32 boards have enough memory, but smaller or older ESP32 models might meet limitations through OTA, particularly if the uploaded sketch is near the existing memory limit. If users upload code without a password, the device may become unreachable for future OTA updates, possibly requiring a re-upload of the necessary OTA sketch via serial. While users can add a username and a secret word for safety, this measure might not fully protect the OTA upload page from unauthorized access if someone identifies the specific URL. Improper implementation of the OTA code can lead to potential issues, as it may disable future OTA functionality. Applications The applications of ESP32 OTA include the following. ESP32 OTA applications allow the device’s firmware to update remotely without any physical connection to the device. So this is mainly helpful for IoT devices installed in inaccessible locations, decreasing downtime & maintenance costs. OTA allows for software updates, bug fixes, and feature enhancements to be deployed quickly and efficiently. ESP32 OTA updates are essential in various applications, mainly in embedded systems and IoT deployments.. These updates are significant for industrial automation systems’ maintenance and upgrading without shutting down the whole process. OTA allows smart home devices to receive remote firmware upgrades by ensuring the best performance & feature improvements. OTA updates are significant to update the remote sensors’ firmware & monitoring systems, by ensuring they stay accurate & functional. OTA update provides a suitable method to handle and keep devices in any IoT application, wherever remote access is impractical or limited. Users update smart locks, security cameras, and security systems to ensure they remain safe and functional. Industries employ ESP32 OTA to update the software and systems of machines in automation processes. Technicians update the device’s software in weather stations, environmental monitoring, and remote applications. This OTA updates software in smart farm equipment, irrigation systems, etc. It manages & updates smart home devices remotely in home automation like locks, security systems, smart lights, etc. Conclusion: Thus, ESP32 OTA updates provide a convenient method to update firmware & other files wirelessly on ESP32 devices by removing the physical connections. So this method is mainly helpful for remote deployments & reduces maintenance by allowing bug fixes & enhancements of features without any physical connection. ESP32 OTA update provides a valuable technique to maintain & update ESP32 devices remotely, simplify maintenance, and shorten the update process. Here is a question for you: What is the ESP32 board? Share This Post: Facebook Twitter Google+ LinkedIn Pinterest Post navigation ‹ Previous Drone Technology Advancements : Swarm Technology, BVLOS, Quantum Navigation & ComputingNext › How LTE and 5G Are Powering the Next Generation of Drones Related Content Difference between ESP32 vs Arduino Arduino Due : Pin Configuration, Interfacing & Its Applications Arduino Relay : Circuit, Working, Code, Specification & Its Applications Arduino Sensor – Types and Applications