Page 1 of 1

Not understanding OTA walk-through

Posted: Wed Aug 15, 2018 8:02 pm
by IsaacJones
I have the ESP-WROOM-32 and am using the following "Simple OTA Demo" to try and figure out how this feature works.
https://github.com/espressif/esp-idf/tr ... system/ota

Below is the step-by-step of what I did along with my questions about what isn't working.


1. I copy/pasted the following code into a terminal and it started a server:
cd $IDF_PATH/examples/get-started/hello_world
make
cd build
python -m SimpleHTTPServer 8070


2. I opened another terminal entered cd ~/esp/esp-idf/examples/system/ota, and then make menuconfig and then entered the following information:
(********) WiFi SSID
(*******) WiFi Password
(HTTP Server) HTTP Server IP
- I have also tried entering my Mac's IP address
(8070) HTTP Server Port
(/hello-world.bin) HTTP GET Filename


3. Entered make, and then make flash

4. After then entering make monitor, hello_world started running, but I am at a loss for how to update this "over the air" now... there are no further instructions. All of this was done while the ESP32 was plugged into my Mac. How do I set this up so I can send updates to this code without it being plugged into my Mac?

Re: Not understanding OTA walk-through

Posted: Thu Aug 16, 2018 3:37 am
by kolban
My recommendation would be to look at the sample code and try and "read" it. When you come across an API that you are unfamiliar with, research that in the documentation. Get a feel for what the application is "trying" to do. From a cursory read, it seems that the ESP32 starts up, connects to your local access point and then issues an HTTP GET request to a named IP/port pair. What ever is returned from that call is expected to be an ESP-IDF bin file ready for writing into the next OTA partition. When written, the ESP32 boots and runs that app.

Re: Not understanding OTA walk-through

Posted: Thu Aug 16, 2018 1:33 pm
by fly135
IsaacJones wrote:4. After then entering make monitor, hello_world started running, but I am at a loss for how to update this "over the air" now... there are no further instructions. All of this was done while the ESP32 was plugged into my Mac. How do I set this up so I can send updates to this code without it being plugged into my Mac?
How do you know that it didn't get updated? Not really sure what your question is. Just plug the micro usb into a wall wart power supply and the esp32 will run the app you programmed into it without being attached to your Mac.

John A

Re: Not understanding OTA walk-through

Posted: Thu Aug 16, 2018 3:46 pm
by username
How do you know that it didn't get updated? Not really sure what your question is. Just plug the micro usb into a wall wart power supply and the esp32 will run the app you programmed into it without being attached to your Mac.
He's asking how to perform a OTA update after he changes his code and re-compiles it.

FWIW IsaacJones, I am with you on this. The one thing I figured would be very well documented, and have a plethora of examples would be OTA, though sadly not the case.

Re: Not understanding OTA walk-through

Posted: Thu Aug 16, 2018 3:53 pm
by kolban
Howdy guys,
I'm a big fan of good docs ... can I ask that we look at the following:

https://esp-idf.readthedocs.io/en/lates ... m/ota.html

Let's see if we can't figure out what might be missing from these docs that might make the sample clearer. I believe the sample is an illustration of using these APIs and is not meant to be understood nor used just by examining the code without also reading the associated documentation. I for one would be delighted to hear questions on using these APIs and then, together, as a community ... we can start to fill in the blanks and improve the materials.

Re: Not understanding OTA walk-through

Posted: Thu Aug 16, 2018 6:10 pm
by plajjd
Thanks, Kolban! I appreciate your input and your desire to help us all succeed.

Can you help me find documentation on the "esp_https_ota()" function? I see it referenced in the forum, and in some code examples, but would like to understand what it is actually doing.

Re: Not understanding OTA walk-through

Posted: Thu Aug 16, 2018 6:16 pm
by kolban
This function appears to be documented here:

https://esp-idf.readthedocs.io/en/lates ... s_ota.html

If we think about OTA at a high level, its purpose in life is to obtain a new binary image, write that binary image into an area of flash, flag that flash as the source of program on next boot and then reboot.

When we wish to replace one version of an app with another, we can't replace/delete the original app until/unless we have succesfully (and completly) downloaded a new version. Thus we have the concept of at least 2 OTA partitions. One would hold the currently running app and the other would hold the new app that is being downloaded. Only when the new app is in place, can we "switch" to the other. The OTA APIs give us the capability to begin a new write of an OTA app, write the data and then complete the write. However, nothing in the OTA API talks about "where" the new app comes from. That is left as an exercise for the reader (us). A typical story is that we would download a new app using HTTP. Since this story is so common, Espressif have provided a "helper" function which is esp_https_ota. Its purpose is to form a connection to a remote Web Server and initiate the download of data. That data is what will be written into the OTA partition for the new app.

Re: Not understanding OTA walk-through

Posted: Thu Aug 16, 2018 6:21 pm
by fly135
username wrote:
How do you know that it didn't get updated? Not really sure what your question is. Just plug the micro usb into a wall wart power supply and the esp32 will run the app you programmed into it without being attached to your Mac.
He's asking how to perform a OTA update after he changes his code and re-compiles it.

FWIW IsaacJones, I am with you on this. The one thing I figured would be very well documented, and have a plethora of examples would be OTA, though sadly not the case.
Oh darn, my bad... I thought he was using an OTA example. Looking back I see it's a hello world.

My recommendation is to pick an example program that starts the wifi, the edit it to have an OTA function that has 3 lines of code...

Code: Select all

esp_http_client_config_t client;
client.url = "http://mysite.com/mycode.bin;
int ret = esp_https_ota(&client);
caveat: The esp_https_ota module requires https and a certificate. But if you go into the code it's simple to just comment out the check for cert and https.

Re: Not understanding OTA walk-through

Posted: Fri Aug 17, 2018 1:57 pm
by IsaacJones
fly135 wrote:
username wrote:
How do you know that it didn't get updated? Not really sure what your question is. Just plug the micro usb into a wall wart power supply and the esp32 will run the app you programmed into it without being attached to your Mac.
He's asking how to perform a OTA update after he changes his code and re-compiles it.

FWIW IsaacJones, I am with you on this. The one thing I figured would be very well documented, and have a plethora of examples would be OTA, though sadly not the case.
Oh darn, my bad... I thought he was using an OTA example. Looking back I see it's a hello world.

My recommendation is to pick an example program that starts the wifi, the edit it to have an OTA function that has 3 lines of code...

Code: Select all

esp_http_client_config_t client;
client.url = "http://mysite.com/mycode.bin;
int ret = esp_https_ota(&client);
caveat: The esp_https_ota module requires https and a certificate. But if you go into the code it's simple to just comment out the check for cert and https.
Thanks! I am super new to this though... Do you have a wifi example in mind? Also, where do I place that code in the program? And do you know why I am having trouble with this particular example?

Re: Not understanding OTA walk-through

Posted: Sat Aug 18, 2018 2:22 pm
by fly135
I reread your original post again and you did build and flash the ota example. However you also said that the esp32 ran hello world when you ran it again. It should have run the ota example. And the ota example program has the wifi code in it.

The real question is why your esp32 ran the hello world example after flashing the ota example. The ota example program should download and flash the bin file you specified in the menuconfig. What is that bin file? The hello world example. And what ran when you did a make monitor? The hello world program.

So we are back to my original post....

"How do you know that it didn't get updated? "