If you have been a regular viewer of Techiesms you must know that we love working with ESP32. It has got so many of mesmerizing features. It has got great processing powers and BLE along with Wi-Fi.
What is OTA?
OTA stands for Over The Air. It allows uploading a new program to ESP32 using Wi-Fi instead of connecting the ESP32 to a computer via USB to do the update. It is extremely useful in situations where you don’t have physical access to the module. One such example is mentioned here.
What is the need of OTA?
Let us say, you have created a phenomenal project using ESP32. You fixed it in your home and powered it up. Everything is working fine and you have got comfortable into your smart home. But one day you need to make slight changes to the code or maybe change the code with updated version of libraries and stuffs or maybe add some more features to it. Will you like the mess of plugging out the whole module, removing the connections, plugging it to your PC, uploading the code, re-doing the connections and then setting it all up again?
Well no! No one will. That is where OTA kicks in. For establishing OTA with ESP32 you need to include few extra lines to your code and after that you can upload the codes wirelessly over the air.
How to implement OTA with ESP32?
There are two ways to perform an OTA update to your ESP32 board.
- Basic OTA – Updates are sent via Arduino IDE
- Web updater OTA – Updates are sent via a webpage/web browser.
In this tutorial we will be implementing Web-Updater OTA. You can read about BasicOTA from HERE!
For using Web-updater OTA feature with your ESP32 board. You just need to follow these three steps.
- Upload the Web-updater sketch to ESP32
- Access the Web-server created by your ESP32
- Get the binary file of your code
- Done! Upload the code Over-the-Air through web
Step 1 :- Uploading the WebUpdater sketch.
The ESP32 board does not support OTA updates by default, hence you need to upload the new firmware in order to perform the OTA updates.
This is a mandatory step as this will later allow you to push the new codes wirelessly via Wi-Fi.
Firsty, you need to have the ESP32 boards package installed in your Arduino IDE. If you don’t have those then you can watch this video of mine to get started with ESP32.
After installing the boards. Go to File > Examples > ArduinoOTA > BasicOTA.

This is the sketch that you need to install in order to give your ESP32 the power of OTA.
The changes that you need to make in the code are ssid and password. You need to give this credentials so that the ESP can connect to your router in order to receive the updates. Once you are done with those, go ahead and upload the sketch.
Step 2 :- Access the Web-server created by your ESP32
Once you have uploaded the Basic OTA sketch. Open your Serial Monitor on a baud rate of 115200. If everything went alight then you will see IP Address printed at the end of the monitor. Note the IP address.

Visit to this IP address with any browser, make sure you are connected with the same WiFi network as your ESP board.

You’ll be greeted with a page like this. Both the default username and password are “admin” You may change them according to your wish in the code itself. Just change this line of the code.
"if(form.userid.value=='admin' && form.pwd.value=='admin')"
Step 3 :- Get the binary file of your code
After you login, you’ll see the page from which you can upload sketch but for that we firstly need to generate the bin file of our sketch.
Below is the code that we are going to upload to our ESP32 over the air. The code is for blinking a LED while also keeping the OTA feature intact.
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Update.h>
const char* host = "esp32";
const char* ssid = "xxxxxx";
const char* password = "xxxx";
const int led = 2; // ESP32 Pin to which onboard LED is connected
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><b>ESP32 Login Page</b></font></center>"
"<br>"
"</td>"
"<br>"
"<br>"
"</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 =
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"
"<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) {"
"}"
"});"
"});"
"</script>";
/*
* setup function
*/
void setup(void) {
Serial.begin(115200);
pinMode(led, OUTPUT);
// 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: %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);
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);
}
}
Now we need to generate the bin file of this code. For this just go into the sketch tab in Arduino IDE and choose export compiled binary.

Step 4:-Done! Upload the code Over-the-Air through web
Now that you have generated the binary file of your code its time to upload the code to the board through the web page.
Open the /serverIndex page in your browser. Click on Choose File… Select the generated .bin file, and then click Update.

Wait for few seconds……..
And Wallah! The code will be uploaded to the board over the air without the Arduino IDE. How cool is that?
Conclusion:-
Yeah, I know it is a bit of headache to include the Basic OTA sketch to each of your code but the functionality it gives is flawless. If you are going to sell your product in the market then you need to provide your customers with an option to update the firmare when needed. That can easily be fullfilled by this OTA feature. Still the implementations depend from user to user.
Thank you for your article.Much thanks again. Will read on…
Hello everyone , can anyone recommend where I can purchase Apple Flavor Dog Treats CBD Pet Product By TropiCBD?
I want to to thank you for this great read!! I absolutely loved every little bit of it. I have got you bookmarked to look at new things you postÖ
Really enjoyed this blog article.Thanks Again. Great.
I appreciate you sharing this post.Much thanks again. Really Cool.
I loved your article post. Keep writing.
Muchos Gracias for your blog post.Really thank you! Really Cool.
I really liked your blog article.Really thank you! Want more.
Very informative blog.Much thanks again. Really Great.
http://www.hydroxychloroquinex.com/ hydroxychloroquine in canada for sale
stromectol over the counter ivermectin injection
I really enjoy the blog article.Much thanks again. Keep writing.
Tips very well used.!college essay writing company write my paper master thesis writing help
Looking forward to reading more. Great blog post.Really thank you! Want more.
hello!,I like your writing so much! percentage wekeep in touch more approximately your post on AOL?I need an expert in this area to resolve my problem.May be that is you! Having a look forward to peer you.
Really appreciate you sharing this blog article. Really Great.
Outstanding post however , I was wondering if you could write a litte more on this topic?I’d be very thankful if you could elaborate a little bit further.Bless you!
What’s up, yup this submit is really good and I’ve figured out lot of things from it regarding blogging. many thanks
Aw, this was a really good post. Taking the time and actual effort to make a really good articleÖ but what can I sayÖ I hesitate a lot and never seem to get nearly anything done.
I really like and appreciate your article post.Really thank you! Cool.
particularly wonderful read!! I definitely appreciated every little
Major thanks for the article post.Really looking forward to read more. Cool.
Hi are using WordPress for your blog platform?I’m new to the blog world but I’m trying to get started and setup my own. Do you need any coding knowledge to make your own blog?Any help would be really appreciated!
Safe canadian pharmacy tadalafil online pharmacy Prozac
Thank you for your blog article. Really Cool.
Wtaqyj It is generally applied to those with a chronic ele vation of serum creatinine to [url=https://newfasttadalafil.com/]Cialis[/url] comprar cialis online Amoxicillin High Dose https://newfasttadalafil.com/ – Cialis Ufrywv
A round of applause for your article.Really thank you! Much obliged.
Hey, thanks for the article.Thanks Again.
Thanks for the good writeup. It in reality was once a enjoymentaccount it. Look advanced to more delivered agreeablefrom you! By the way, how could we keep up a correspondence?
Major thanks for the post.Really looking forward to read more. Much obliged.
It as hard to find experienced people about this topic, but you seem like you know what you are talking about! Thanks
Very neat blog post.Really thank you! Great.
Pretty nice post. I just stumbled upon your blog and wanted to mention that I’ve truly enjoyed browsing your blog posts. In any case I will be subscribing for your rss feed and I am hoping you write once more very soon!
stadium village apartments rentberry scam ico 30m$ raised apartments in wake forest nc
I appreciate you sharing this post.Thanks Again. Cool.
On Line Worldwide Amoxicilina With Free Shipping
Looking forward to reading more. Great blog article.Really thank you! Much obliged.
I value the blog article.Really looking forward to read more. Great.
Im thankful for the post.Really thank you! Really Great.
I am so grateful for your article post. Awesome.
I really liked your post. Keep writing.
Awesome article.Much thanks again. Cool.
It’s going to be ending of mine day, however before finish I am reading this wonderful paragraph to increase myknow-how.Also visit my blog: Keto Smooth Ingredients
It’s really a great and helpful piece of info. I’m happy that you simply shared this useful info with us. Please stay us up to date like this. Thanks for sharing.
ivermectin cream 1 ivermectin lotion – ivermectin 50ml
Really appreciate you sharing this post.Really thank you! Want more.
Thanks for sharing, this is a fantastic blog article.Really looking forward to read more. Awesome.
I am sure this post has touched all the internet users, its really really nice article on building up new blog.
Really informative blog post. Keep writing.
Thanks so much for the post.Much thanks again. Great.
Thanks-a-mundo for the blog.Much thanks again. Keep writing.
Hi there, just became alert to your blog through Google, and found that it is really informative.I’m gonna watch out for brussels. I’ll be grateful if you continue this in future.A lot of people will be benefited from your writing. Cheers!
I am not sure where you’re getting your information, but goodtopic. I needs to spend some time learning more or understanding more.Thanks for excellent info I was looking for this information for my mission.
A motivating discussion is worth comment. I do think that you ought to publish more on this subject matter, it may not be a taboo matter but usually folks don’t talk about these topics. To the next! Cheers!!
Hi there friends, its wonderful post concerning educationandfully defined, keep it up all the time.