#332 ESP32 OTA tutorial with tricks (incl. OTA debugging)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I would like to remind you of a handy ESP 32 concept over the air or OTA update a simple and efficient replacement for the serial cable for devices which are not easily reachable or for pair pone ESP 32 modules and as usual I will add a few tricks and helpers gritty youtubers here is the guy with a Swiss accent with a new episode and fresh ideas around sensors and microcontrollers remember if you subscribe you will always sit in the first row in this video we will learn how to use ESP 3200 ta create a basic sketch template for all our new projects I will show you some tricks like remote debugging if this simple OTA is not enough I will show you other frameworks and as usual I included a one last thing recently a viewer complained that the USB connector was broken on one of his ESP 32 ports but he didn't want to throw it away and last week i ported my old Morse a trainer project to the ESP 32 and put it into this housing without an opening for a USB cable both perfect use cases for OTA so what is OD a if our sketch is OTA enabled we can select a network port instead of a serial port for uploading and the sketch is uploaded over the air or OTA yes you heard right the sketch has to have the OTA functionality unfortunately it is not part of the bootloader this is why we have to include it in all our sketches and upload the first OTA enabled sketch by a serial during OTA the arduino ide sends the code and the ESP 32 buffers it in a secret area of memory checks it and only if everything is ok loads it to the right memory and reboots into the new code so OTA is safe against transmission problems if something happens during transmission usually you can restart the upload in the worst case you have to reboot or unplug your ESP from power for a moment because this procedure needs memory space you have to select the right partition before you upload sketches the default configuration works fine if you select one with no ot8 unfortunately your upload still might work but maybe your ESP suddenly will crash and you do not know why after checking the petition we can start with our OTA templates sketch it is straightforward because I put all the needed code in a second file called OTA dot H we only have to include this file using quotation marks because it is in the same directory in setup we only need these two lines my first tip I give all my boards a unique name why if you open the port selection menu you see all audio enabled devices in your network with their IP address but who knows which address belongs to which device and if all have the same name the chance you upload your sketch to a wrong device is very high the unique name is prominently displayed in the port's selection menu problem solved the next line calls the needed stuff hidden in the second file that's all except for one general thing I strongly suggest creating a credentials dot H file in your library directory it's content is simple just these two lines like that you define your SSID and your password in one place and all your sketches use this definition and if you happen to put your stuff on github you are pretty sure your passwords are not published if you do not want such a file you have to copy these two lines into your ot a dot H file and delete the included credentials dot H the last thing you have to do is to add this line somewhere in loop and here is the second trick OTA only works if this line is called once in a while if you for example use a long delay of more than about five seconds your upload will always crash and you have to upload a new sketch via USB the same thing happens if your sketch loops somewhere for example my Morsy trainer waits for keyboard input during this time ot8 did not work until I added this line also in the keyboard read loop fortunately you can call it as often as you want and as you see its execution time is only 41 microseconds less than a tenth of a millisecond the third trick if you copy the folder of the template sketch in your library directory you can select it from the examples and because I replaced the O in ot a with a zero it always sits in the first row in the future you just start with this template instead of the standard setup and loop and add your code very simple your sketches are automatically OTA enabled you even can upload the bear template project and your ESP is OTA enabled but unfortunately you lose the serial dot print functionality for debugging we have two variants to solve this issue in my Morsy trainer I added a small pin header for an FTDI board if I wanted to debug I plucked one in and got a serial connection to potty this is OK during substantial development because it keeps the connection also during reboots I added a small library called telnet stream to my OTD template it can redirect serial.print stateman to telnet in the arduino ide you see the IP address of your port if you use putty to establish a telnet connection to this IP address you have a serial connection for debugging but you have to reestablish it after upload with these two things in place we have all for our future completely wireless ESP 32 adventures if you want more there are two additional ways Wi-Fi manager should now also run on the ESP 32 it offers OTA + configuration screens that you can change your password from a mobile phone this can be interesting if you want to deploy your device into other networks or if you often change your network credentials and IOT app story comm is the deluxe version with everything Wi-Fi manager has plus lots of management capability for a whole fleet of ESP thirty twos or esp8266 is in video number 225 you find more information summarized because the sketch and not the bootloader contains the OTA functionality we have to upload the first OTA enabled sketch using a serial connection and we have to include this function in all the following sketches to make this easy I created a simple OTA enabled template sketch if we place it in the libraries folder we can use it directly out of the examples menu it only needs two additional lines in setup and one in loop one is the setting of a unique name for the board quite important if you do not want to upload your sketch to the wrong ESP 32 we have to pay attention that the Arduino OTA taught handle is frequently cold otherwise we will get a timeout and have to upload the next sketch via serial because I included the telnet stream library we even get serial debugging over-the-air I created the sketch for the ESP 32 maybe somebody Forks my github and adds support for the esp8266 that would be cool one last thing Morse code depends on a stable timing in video number 327 I used interrupts to create timing because the ESP 32 has artists a real-time operating system included I tried it this time differently I created a second artists task this is very easy if we copy the structure of video number 168 the second task runs in parallel to the loop task and I can use a simple delay for the timing our toast takes care that during this delay the processor power can be used by loop so this second task behaves very similarly to a interrupt service routine without using interrupts this makes me think if I should invest a little more time into our toes we will see what the future brings as always you find the relevant links in the description I hope this video was useful or at least interesting for you if true please consider supporting the channel to secure its future existence thank you bye
Info
Channel: Andreas Spiess
Views: 79,983
Rating: undefined out of 5
Keywords: AliExpress, Aliexpress quality, arduino, arduino project, beginners, BJT, diy, do-it-yourself, eevblog, electronics, esp32, esp32 datasheet, esp32 project, esp32 tutorial, esp32 weather station, esp8266, esp8266 project, greatscott, guide, hack, hobby, how to, iot, lora, n-channel, nodemcu, p-channel, pnp, project, simple, smart home, transistor, Transistor Tracer, Transistor tutorial, ttgo, tutorial, wemos, wifi, ESP32 debugging, esp32 ota, esp32 ota tutorial, esp32 ota debugging, over the air
Id: 1pwqS_NUG7Q
Channel Id: undefined
Length: 10min 16sec (616 seconds)
Published: Sun May 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.