The EASY Guide To Over-The-Air (OTA) Updates With ArduinoOTA

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
over-the-air updates or OTA allows you to upload code to your electronics Project without having to have it physically connected to a computer you can like cut your cables in this lesson we'll walk through wirelessly uploading sketches to your esp32 board using the Arduino OTA library now this video is going to focus on just the minimum stuff you need to actually get over-the-air updates to work in fact it's like two functions from the library that will be able to use to make this work let's go ahead and dive in all right before we get to the code I just want to talk about code flow real quick it's really straightforward this should only take us a moment but so think about let me zoom in a little bit think a little bit about an Arduino sketch right we've got setup and we've got Loop setup happens once Loop happens over and over and over so inside setup there's two minimum things you need to do to make this OTA stuff work the first is you got to connect to a Wi-Fi so you'll connect to a Wi-Fi network and the next thing you need to do is begin the Arduino OTA and this is literally a function call so this is one line of code right here so this is super easy then inside the loop there's a single function that you need to include that will handle the OTA updates and then other than that you just write your own code so you know the loop goes over and over and over and every time through the loop you'll be checking to see if there's an update and if there is it will get handled by this single function call so okay pretty straightforward let's go ahead and code this up all right here I am in the Arduino IDE in a blank sketch and what I'm going to do first is just write a couple comments just to kind of line up what we need to do here okay so we need to include some libraries we need to set up our Wi-Fi credentials you know like what is the name of the network and what's the password well then we need to connect to Wi-Fi we need to begin OTA and then in the loop we need to make sure we handle OTA and then below that is where we put our own code so let me go ahead and write in some of these functions here and we'll talk about it okay all right so you can see not a lot of code here let's go ahead and talk about this so including libraries you're going to need two libraries as a minimum first you'll need the Arduino OTA Library so that's what's going to enable these over the air updates and then you'll need the wi-fi.h library and that's just for connecting your esp32 to Wi-Fi then you know you set up your Wi-Fi credentials this is just your network name and your password um obviously you'll change these to your own and that's kind of like above setup right so not much there in setup first we need to connect to Wi-Fi so I'm just using the begin function from the Wi-Fi Library you pass in that SSID and password and it's going to connect and it defaults to Wi-Fi station mode which basically says hey it makes this device a thing that can connect to a Wi-Fi network and what this allows esp32 to do is connect to the Wi-Fi network that you specify but that might take a moment and so what you want to do is kind of wait until that's happened so we just kind of hold here until it's connected and after that we use our first function from the Arduino OTA Library which is the begin function and all that does it doesn't take any parameters it's just going to get the OTA set up and that is going to happen in setup once we get into the loop we have the other Arduino OTA function handle that we call so just Arduino ota.handle and this is what we'll be checking for updates and handling that update inside the loop so any code you have is just going to go right below here and this is it hopefully you can see that this is really the scraped down absolute minimum code that you need to make this over the error update work like you could do some other stuff in here you know like maybe uh if it doesn't connect you restart the Wi-Fi and you know maybe you print some stuff off and there are some other functions in the Arduino OTA library that you can take advantage of but I really wanted to boil this down to the absolute minimum code you needed and that's what this is if you want to check out a sketch that has some more of these functions demonstrated then go up to file examples Arduino OTA basic OTA and this will demonstrate kind of some more stuff that you can do some other functions in here but you can see it's got a bit more going on and again I just wanted to get it down to the bare minimum so we're just including libraries setting up Wi-Fi credentials connecting to Wi-Fi Arduino OTA begin and then in the loop Arduino OTA handle so now let's go ahead and upload this and just so you know I have a esp32 vroom da module any esp32 should work fine with this and I have it physically connected to the computer so the first time you load this OTA code you'll have to have your esp32 board physically connected to your computer to upload the code after that you'll be able to do it wirelessly now there's one really really really super important point I want to make here and it's that every time you upload new code to your board it needs to include at least this minimum OTA code so like let's say I wirelessly uploaded some code to this board third and it just had like the blank sketch and there was no reference to OTA well that blink sketch is going to replace this sketch and so once you've done that you will have overwritten your OTA capability and you're not going to be able to wirelessly update your board again so every time you upload code you need to include the OTA functionality it's not like Arduino OTA is like setting up the board forever for these OTA updates it's literally the code itself is what's making this work it's not some process running in the background or or something like that so just to say it one more time every time you upload code to the board if you want to keep doing over-the-air updates you need to include that OTA code so I've just uploaded this code to my esp32 and what I'm going to do is I'll go ahead and unplug it and then I've got a little backup battery power supply here and I'm going to go ahead and plug it in so this should power this up okay there it is so it's back on again this is just a little backup battery power supply thing nothing special okay so now my esp32 is powered and it is not connected to my computer no physical connection there and now what I can do is I go to the board and Port selection in the Arduino IDE and look at what shows up there's a network Port that now shows up and it says unknown you can actually name that again that's something you can do if you check out that other basic OT Sketchers a way to name it so it's a little more clear to identify but and now you just select this port and it's that easy it's going to ask me what it is I'll set the board and then I hit OK and now I can literally just kit upload and I can upload new code to this board that's pretty sweet now one quick note if I try to open up the serial monitor you'll get a little error that says hey this there's no serial monitor for the network protocol so as far as I understand you're not going to be able to use that but still hey this is pretty sweet now another way to select the port is if you just come up to tools port and under the port it will list the network ports and that's the same for Arduino IDE 1.0 you can just look right under the network ports just like this so this works perfectly fine in Arduino 1.0 I will note if you are using Arduino ide1 what I found is that I had to close my Arduino IDE and open it again in order for the network port to show up maybe that was just my setup but anyway okay so now we're connected but chances are you probably think I'm totally lying like I'm just making this stuff up so I'm going to prove it to you right now what I'm going to do is I'm going to add a little blink code down in the loop and then I'm going to upload it and I have a LED circuit set up here so so let's see if this is just make believe or not kind of feels like it [Music] okay so I just added some blink codes you know set the pin mode pin number and then just a digital rate pretty uh basic stuff here and I'm going to go ahead and click upload well now it's asking me for my password whoa what's that well that is the network password so I'm going to go ahead and put that in here and then I click upload now it's worth noting that the computer that you're working on you know to wirelessly upload this code it needs to be connected to the same Wi-Fi network as your esp32 is connected to so my computer which is not connected to my esp32 right now is connected to the same Wi-Fi network as the esp32 that's kind of cool I mean that looks like I don't know tronish or something oh do you see that see I'm not a liar it's still that was not smoke and mirrors that just happened that is so cool all right now uh let's do this let's uh let's say uh I don't know I was like man that's too slow and maybe this is like who knows maybe it's in some weird place I just can't reach it easily but I want to be able to like update that code what do I have to do well I need to make sure to include the Arduino OTA code because if I don't do that I'm gonna not be able to do it anymore let me uh let me change this just let's speed this up to uh tenth of a second let me upload that again let's see how this works all right now I'm going to upload again but it's not showing my network pork what did I do I didn't change anything it should be showing a network Port so uh to troubleshoot this I'm just going to close the IDE and open it again just to be clear when I open this up I'm not seeing the network Port shown so let me just try closing it and reopening it all right and that did it now it's showing back up I promise you I didn't touch the esp32 to reset it or anything like that I just had to restart the Arduino IDE I'm not sure why that is who knows but I'm going to go ahead and select it I'll go ahead and upload this code gotta enter the password again okay I was able to upload again I guess I did have to restart the Arduino IDE I haven't had to do that in the past at least in Arduino ide2 maybe that's just something that happens once in a while a good troubleshooting step all right well I'm glad you've got this Arduino OTA code down the next video you should watch is this video right here it is an Arduino master class and it will get you up and running with Arduino in no time so you understand all this background information like setup and loop and variables and control structures all that stuff you're going to get it action-packed this video right here
Info
Channel: Programming Electronics Academy
Views: 20,407
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
Id: 7Xdsc1qqoro
Channel Id: undefined
Length: 11min 51sec (711 seconds)
Published: Fri Aug 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.