OTA with the ESP32 (Over The Air)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
- [Narrator] So here's the scenario, You have a wifi enabled micro controller, like the ESP32. Maybe you've built a project around it, right? And maybe it's somewhere in your house, and it's connected to the WiFi, and it's doing, you know, cool stuff, whatever that might be. And what you want to do is upload new code. You wanna like, update the firmware, essentially, on that board. But you don't wanna have to drag your computer over to it, plug it in and upload it. Well, what you can do is called an OTA, or over the air update. And that is what you're gonna learn how to do today. It's really not too hard. Stay tuned. (mysterious music) Subscribe to our YouTube channel to get more videos like this. All right, so before we jump in, I'm going to assume that you already have your Arduino IDE set up to work with the ESP32, if you don't, no worries. Just check out our other video really quick on getting the Arduino IDE set up with the ESP32. But, assuming you've done that, this is what we're gonna do. So in order to set up an over the air transfer, we do need to have the ESP32 physically connected to our computer the first time we do it. And what we're gonna do is upload a sketch that will then enable us to do over the air updates. Hopefully that makes sense. So the first time you do it you gotta have it connected to your computer. You upload the code, and then after that you're able to do it over the network, over the WiFi connection. Okay. So the way we are gonna be able to do this so easily, is because we're gonna use a library that somebody has already written for this. And it's called ArduinoOTA, or over the air. Now here's what's really cool: this library, right here, it comes pre-packaged with the ESP32 core. So, if you've already set up the Arduino IDE to work with the ESP32, you don't need to separately download this library. But this library is a good place if you have some questions about how to work it, you know, like how does it work? So you can definitely check out this page. We'll leave a link to this GitHub repository in the description if you want to check it out. This video is sponsored by NextPCB. For $0, you can get a one to four layer PCB. That's right! $0 for a PCB prototype for the first order. They've got special offers going on all the time and $100 coupons for new users. It's easy to get an instant quote. You can upload a Gerber file, and when you do that, it will fill in all this information for you. And that also allows you to use the Gerber viewer. That's $0 for PCB prototype. You can use the link below to register and get that $100 coupon. All right, so the first thing I'm gonna do is, I plug in my ESP32 using USB cable and now I'm gonna select that board. So I'm gonna go up to tools, board, and then you can see here's ESP32 Arduino, and I'm just gonna go down. I've already got it selected, but you get the idea, you just pick the one you want. Right? So, then I'm gonna go to tools and I gotta select the port. And I've got a list here of different ports, serial ports right here, right? And I'm gonna say, yep, that's what I want. Okay. So I've selected it. So now I'm gonna come up to file, examples, and I'm gonna come down to examples for the ESP32-S2, and here is ArduinoOTA. And what I'm gonna do is just select this basic OTA. All right. So here is this sketch, what the heck is going on here? All right, so we include some WiFi libraries, WiFi.h, ESPmDNS, WiFiUdp, and then this ArduinoOTA, again we said that this comes pre-installed. All right, then we need to define our ssid. That's like the wifi network name, right? So, maybe your network name is like 'my house', or whatever that would be here, and then your password, you write that there. And then in the setup, it goes through, it does a serial connection, shows some stuff, "Hey, we're booting.", and then it prints some information out to the serial monitor. Kind of let you know, "Hey, this is, "you know, whether or not you're actually connecting." Right? And then if it connects, what it does is it prints out some information. But I think it prints out like the IP address for you. I mean, a lot's going on here, but all this is handled by this library, which is pretty nice. So instead of just writing the ssid and password in here, what I'm gonna do is make a new tab. I'm gonna call it 'arduino 'secrets '.h'. And then in this file, I'm gonna specify my ssid and password as defines. All right, so, here you can just, you know, you can put what your stuff is and it's gonna be inside quotes, whatever the network name is, and then whatever the password is, you put it inside the quotes. So now what I can do is include that here. All right. Now, ssid is just referring to that defined statement that you set up in the arduino secrets header file, and same here. Now I will say, if you happen to have a 2G network, I have had far more success connecting my ESP32 to 2G networks than I have to our 5G networks. So just a note, if you're having trouble getting the connection going, try the 2G version of your network. So now I'm gonna go ahead and upload this code. All right, looks like that was successful. Now I'm gonna open up the serial monitor window, and all right, looks like it connected. Says IP address is ready. If this isn't working out, like you're having connection issues, like I said, see if you can try the 2G version of your network and also double check that ssid and password, I'm telling you, it's so easy for me to screw that up. I don't know why sometimes, like, when I was doing this, I mixed up, I put my password where my ssid was and my ssid in my password. Like, Sometimes it's the dumb stuff that gets you tripped up. So anyway, okay, so now we're connected. Now that's pretty cool. So, this sketch though, this isn't what I want running on my ESP32. I wanna run some other sketch. Like, that's the whole idea, right? And the code that you're gonna upload is not this sketch. Like, it's gonna be something totally different. So, let's just find something totally different. In this case, I'm just gonna use a simple blink sketch. All right, so I just wanna upload a blink sketch, over the air, to this ESP32. So I'm just gonna go ahead and open that sketch. I happen to have it right here. All right, so here's my WiFi caffeine sketch, right here. It's just a simple blink sketch, right? Gonna turn an LED on and off. So what I'm gonna do, is unplug my ESP32 from my computer, now I've got a battery hooked up, so now it's just running off of battery power, and now I'm gonna go up to tools, and I'm gonna go port, now check this out: network ports. Now I can see this shows up as a network port. That is pretty cool. So I'm gonna go ahead and click on that. So now I'm selected to this network port, so check it out, see that, that is the port I have selected. It's still the same board, right? It's just the port has changed. So now I'm gonna go ahead and upload this. The upload looks a little different, says it's sending an invitation. And now just like that, my board is doing the blank sketch. That is frickin easy. And that's pretty awesome. You gotta admit, I mean you need to change something on the fly, no need to grab it and plug it into your, you know, back into your computer. It's just set up. So that's it. No real rocket science here. I hope you found that helpful. Again, we can do this, thanks to all of the hard work that was done by jandrassy, with this ArduinoOTA, and then all of the folks who've worked on the ESP32 core, man, that's just amazing that we all get to take advantage of all that stuff. It's, it's really cool. So I hope you found that helpful. Thanks again to our sponsor, NextPCB. Check the description for a link to that deal, to get $0 for a one to four player PCB. If you're interested in learning how to do this Arduino programming stuff, definitely check out our training program, at programmingelectronics.com, And I'd love it if you could like this video, leave a comment if you feel like it, And of course, subscribe to the channel to get more videos like this. Thanks a lot. Have a great one. Bye. (bell chiming)
Info
Channel: Programming Electronics Academy
Views: 50,115
Rating: undefined out of 5
Keywords: Arduino, Arduino(Brand), Arduino Tutorial, Arduino Lesson, Open Source Hardware Group, Learning Arduino, Microcontrollers, Electronics, Arduino IDE, Arduino Sketch, Computer programming, C++, Programming Electronics Academy, internet of things, how to, arduino projects for beginners, arduino uno projects, arduino tutorial for beginners, esp32 tutorial
Id: VyCG1MHdw3g
Channel Id: undefined
Length: 8min 38sec (518 seconds)
Published: Fri Feb 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.