ESP8266 Over The Air (OTA) Programming Without Reset Using Arduino IDE (Mac OSX and Windows)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi I'm Cisco with AK robotic and I'm here to share with you another tip for working with your esp8266 microcontroller a fantastic feature of any Wi-Fi capable microcontroller is the ability to update the firmware wirelessly this is known as over-the-air or ot a programming and in another video we saw how to do it for the esp8266 one of the limitations is that every time we want to do any OTA programming a specific line of code needs to be run and that might interfere with what we want to do in the rest of the code so as a way around it in a previous sketch we waited for 15 seconds and if no OTA programming happened then we would run the rest of our application however every time we wanted to do any additional OTA programming we needed to reset the board manually so today I'm going to show you the steps we can take to program the esp8266 wirelessly any time we want for today I'm going to be working with a Windows d1 mini development board I love working with this boards because of their small form factor and the wide availability of shields which allow me to work on projects without doing any wiring I'm also going to be using I use the power bank which will allow me to power the d1 mini and demonstrate the over-the-air programming capabilities I'll leave a couple of links in the description of the video so that you can check these items in my little Amazon shop last time we talked about OTA we started with a built in example and that can be accessed first by selecting an esp8266 development board then by going to the file menu examples arduino OTA basic OTA we modified the code to wait 15 seconds to see if any ot a programming happened and then blink an LED on and off I'm going to pull up that code real quick so we can see how that was done and after filling in some of the variables initializing the pin in the loop function we use a couple of variables to wait around those 15 seconds and run this line of code this is the one I was talking about that needs to be run anytime we want OTA programming to happen if those 15 seconds elapsed then we blink an LED on and off as you can see if we wanted for this piece of code to run again and allow us to update the code wirelessly then we needed to manually reset the board so using the same line of thinking I'm going to make some modifications in order to allow us to program the board wirelessly anytime we want I'm going to start by adding the header file for using the web server class then I'm going to create a web server instance and I'm going to move this to variable definitions all the way up here as well then I'm going to use the server object to create a couple of routes that will allow me to first change this flag and also to manually restart the board by accessing a specific URL path on the server so let's start with restoring the board I'll simply create a route call restart and that'll be an anonymous function which I'll define right here we'll send an OK message with code 200 it'll be just plain text telling us that hey this page was access [Music] then we'll just give it a second for the server to respond then we'll use the restore method of the ESP object which allow us to restart the application code via software we also need to run the begin method of the server object and the handle client method which we need to run whenever we're working with a web server object in the esp8266 I'm going to save this new file simple OTA on my desktop and I'm ready to give it a try I'll go ahead and make sure that I first connect the we Mo's to my USB then I want to go to the Tools menu select the correct board as well as the correct port and I'm ready to upload the code at this point there are a few things that can go wrong so I'll take some time to go over them so in order for ot a programming to happen we need to first install the correct USB drivers typically the CP 2102 or the CH 3 4G if you've done this correctly you should have been able to upload the code like we just did without any problems so now you need to check that both your computer and the esp8266 are connected to the same network if you're using windows then you need to install Apple Bonjour for Windows which will allow you to use the EM DNS protocol that we're using to upload code over-the-air I'll leave this in the description of the video so you can use the link for downloading another thing we need to do is after uploading the code for us to see the new port for doing OTA programming we need to restart there we know IDE and the very last thing is that we also need to restart the esp8266 development board because as I found on a github issue anytime you upload the code the first time you run ESP restore after it it fails so we also need to restart manually the development board at least once so let me go ahead and first restart the arduino ide and then press the reset button on the windows d1 mini development board so with all that being done if I go to the Tools menu ports I should be able to see a new port over the network that corresponds to the development board and if you see it has an IP address which will allow me to upload code wirelessly notice that if I try to open the serial monitor over the network it will not work it says that it's not supported and it makes sense right the serial monitor is meant to monitor that USB connection but now we're connected over Wi-Fi to the development board if we recall what we did before was setting up a new route that will allow us to restart the esp8266 when that's access and when that happens the actual code that allow us to do OTA programming will run so if I go to my browser open up a new tab and access that path [Music] then we see that the board is restarting we noticed that the blinking stopped and right now we would be able to upload a new piece of firmware so that piece of code is working and we'll give it a try I'll go ahead and modify the blinking pattern to be five times a second and I'll go ahead and access that path one more time again the LED tells me that that's working and while those 15 seconds are elapsing I'll hit upload and I should be able to upload the code over Wi-Fi [Music] when the code starts the LED is solid and we see that after those 15 seconds pass now it's blinking much faster another way to achieve the same result is by having a different route that I'll call set flag and in this case we will not restart the esp8266 because that might not be desirable depending on what we're trying to do with the code instead what that route will do is set the OTA flag to be true and when that happens since I've declare it as a global variable this will evaluate it true and that code will run again so when that happens I'll have a similar response by the server instead of restarting we'll say that we're setting the flag we'll need to also reset the time elapsed to be zero and we'll need to do things a little bit differently while evaluating how much time has passed because here we're just saying how many milliseconds have passed since the last restart happened so if we declare a new variable of type 16-bit unsigned integer and I'll call it time start we can set it to be the Malee's when that code is about to be run and then we can use that to compare with the current Milly's by doing a subtraction and set the result to the actual time that has elapsed since this wild loop started running so now we're ready to test this second route out if we go back to our web browser we can refresh the page that we set the board go back really quickly to the Reno IDE and upload the new code okay so now we have this new router available but we need to change the code to upload it one more time and see it in action so now instead of going with a faster blink I'll go with a slower one so that it blinks every two seconds and I'll go ahead and go to my browser go to the new route set flag and once again this only buys me 15 seconds so I need to be quick after accessing this seeing that the webpage responded go back to the Reno ID already made the change to a slower blink and we'll see the result it's currently uploading and after 15 seconds path we see that the new code was uploaded over-the-air now that everything is working you may be wondering well are we really uploading the code via Wi-Fi or are we still doing it over USB and as one that's also skeptical I'm willing to put it to the test so that's why we have a USB power bank so that we can unplug the board go ahead and connect the power bank so I'll go to my Arduino IDE I'll change back the delay to be a hundred and I'll go back to my browser and use any of the two routes that we set up in code I'll use the same one we just used the set flag and as soon as I reload the page I see that the code runs and is currently waiting for that OTA programming to happen so without any delay I'll go ahead and click upload and I see it in fact uploading I see that the OTA code started running and after those 15 seconds I should see a faster blink that the one-second delay we had before so there we have it I showed you the necessary steps we could take for our over-the-air programming code to be able to run whenever we wanted it so that we can program the esp8266 wirelessly if you like my videos I invite you to go to my patreon page and chip in a buck or two it really helps me put in more time to the videos and release them a little bit quicker but whatever you do don't forget to Like subscribe or leave me a comment I'm also very active on social media you can follow me on Twitter Instagram or Facebook and a lot of people have been using the community tab of the channel to communicate with me and suggest what should be the next topics I should cover on my next video until next time
Info
Channel: ACROBOTIC
Views: 36,026
Rating: undefined out of 5
Keywords: ESP32, ESP8266, Arduino, IDE, NodeMcu, Tutorials, Makers, Learn, Guide, IoT, Internet Of Things, Raspberry Pi, Wireless, Communication, Weather, Creative, Sensor, Python, Programming, C++, Beginner, Electronics, DIY, MicroPython, 3d Printing, CAD, Fusion 360, Education, Tutorial, Intro, Introduction, Web, Developer, HTML, Datalogger, Project, Sensors, Data, Visualization, Webserver, Server, Client, App, WebApp, Wemos, Robot, Robotics, Robots, Easy, Adafruit, Sparkfun, OS X, Windows, Linux, Embedded, Kickstarter, RC, Fun, Build, Engineering
Id: 3aB85PuOQhY
Channel Id: undefined
Length: 14min 52sec (892 seconds)
Published: Tue Oct 02 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.