#32 Internet of Things with ESP8266 #4: Upload Programs Over the Air (OTA)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
create see youtubers here is the guy with a Swiss accent again I started the adventure to create a platform for my future things which are connected with the Internet as mentioned in the previous videos I was so far able to connect to a web service program the ESP modules even when they are soldered on a small PCB and load some initial information from the smartphone to the module programming with my programmer and the pogo pins is not easy if the thing is not reachable because it's built into something so the guys around even developed a completely new method to load the software on an esp8266 module we now can load it over the Wi-Fi network or as engineers say over-the-air the abbreviation is OTA this is extremely convenient and in addition quite fast in this video I show you how to do it and of course also some tricks I learned during my experiments how is it done even and his friends took care that the necessary programs are already implemented in the Arduino one point 6.5 version so on our computers everything is already there in the ESP sketch however some additions have to be made to our normal sketches just at the beginning OTA works only with 4 megabyte flash chips these chips are currently used in the ESP 12 II modules to find out you can run a sketch and get the size of your flash currently my ESP or 107 and 201 only have 512 K flash and cannot be used for OTA I already ordered bigger flash chips and if successful I will show you in a later video on how to change them let's start from what we know in the old world we load a sketch to the module using serial communication on the ESP s and also on the arduino z' there is a program called bootloader which takes all the necessary steps on the modules many arduino users even do not know about this program because it's flashed during production I call this bootloader serial bootloader because serial boot loaders wait for input on the serial line they are useless in the over-the-air world we need a new Wi-Fi bootloader function on the ESP currently we have to create this vibe bootloader ourselves and it is part of our normal sketch unfortunately it has no protection mechanism against unattended changes like the serial boot loaders the principle is the same we have to put our modules somehow in a Wi-Fi bootloader state and then it is ready to accept the sketch from the IDE very similar to the procedure with a serial line after the upload the module boots and we have to make sure it ends in our regular sketch I show you first how simple it works we load the example provided with the IDE and adapt the access point name and password that the module can connect to our network after a while a new port shows up the wireless connection to our module you choose the OTA communication protocol and this sport the rest stays the same and off you go with uploading a sketch very simple in the OTA mode of the IDE the serial console does not work anymore and I have to use a trick to show you what happens during upload I use another serial communications program called potty to connect to the normal serial adapter then you still are able to see the result of serial print commands you see here if I reset the ESP it goes directly into this Wi-Fi bootloader mode connects to the Internet and waits for input from the arduino ide you see here its IP address after the upload the module automatically resets itself and again waits for programming input of course in future sketches we have to make sure that the sketch goes into normal operation after a successful OTA upload but for now we loaded a new sketch without any physical connection to the module through the air awesome let's look into the Wi-Fi bootloader sketch it consists of two parts one part which has to be in the setup and the other part which has to be in the loop in order to use our ESP module not only for a software update but also for real applications we have to add our normal sketch in both areas set up and loop just after reboot the sketch has to decide whether it wants to do upload or normal operation we have to find a way to signal the board if we want to upload a new sketch or run it here is my example in my thing I need anyway to button switches for the normal operation so during startup if both buttons are pressed the sketch goes into the Wi-Fi bootloader mode and after the uploading of the sketch the module goes directly into normal operation because I did not push the two buttons anymore simple trick now I want to show you that this really works I change the welcome text and upload the program as you can see the new sketch was really uploaded let's now have a closer look at the code I will not cover the technicalities of the OTA coding there are much brighter people out there to explain that I include a link below to the coding I used I unleash oh you how to embed the two code snippets into your normal sketch first during startup I have to check the two buttons or you do something else to make sure that the ESP knows that you want it in the Wi-Fi bootloader mode then I set the OTA flag and do the part of the OTA script which has to be placed in setup I call this part o da in it if the buttons are not pressed the sketch continues into normal operation and the OTA flag is set false my loop is very simple if the OTA mode was selected the sketch goes to the OTA receive part and if not it goes to the normal loop that's all again very simple with Arduino Sui all use serial communication for debugging as I said before this does not work here but I already showed you the trick I use connect a simple USB to serial adapter and a small program called putty to show the results of the serial communication like that we can debug as usual of course this procedure is not used for modules placed in things but to test your sketch it is a good way I have also to mention that this procedure is not yet completely reliable sometimes it does not work and the upload is interrupted without an obvious reason unfortunately then the sketch was destroyed and I had to load it the old way through the serial cable but I know these guys work hard and I'm sure they were resolve the issues or at least make sure that during an unsuccessful load we do not lose the original program and can try another time so as a summary my workflow is as follows I still use serial communication for development with a note MCU board this is more convenient but from time to time I load the release to the thing over-the-air just to check if everything also works in the target system before that I always upload it once over-the-air to my note MCU port to make sure that the OTA part of my sketch really works before I flash it to my thing this was all for today in the next video I will look deeper inside the coding of such things to make them stable and responsive I hope this episode was useful or at least interesting for you bye
Info
Channel: Andreas Spiess
Views: 90,883
Rating: undefined out of 5
Keywords: ESP8266, Internet Of Things (Industry), electronics, hobby, do-it-yourself, Arduino (Brand), heck, EEVblog, illett, adafruit, darrah, osh, perks, apocalyptic, greatscott, hackaday, linux, C++, instructables
Id: GoQXOLB50HA
Channel Id: undefined
Length: 9min 58sec (598 seconds)
Published: Fri Nov 27 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.