Not understanding OTA walk-through

IsaacJones
Posts: 2
Joined: Wed Aug 15, 2018 7:39 pm

Not understanding OTA walk-through

Postby IsaacJones » Wed Aug 15, 2018 8:02 pm

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?
Last edited by IsaacJones on Fri Aug 17, 2018 1:59 pm, edited 1 time in total.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Not understanding OTA walk-through

Postby kolban » Thu Aug 16, 2018 3:37 am

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Not understanding OTA walk-through

Postby fly135 » Thu Aug 16, 2018 1:33 pm

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

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: Not understanding OTA walk-through

Postby username » Thu Aug 16, 2018 3:46 pm

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Not understanding OTA walk-through

Postby kolban » Thu Aug 16, 2018 3:53 pm

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

plajjd
Posts: 54
Joined: Thu Jul 05, 2018 11:47 pm

Re: Not understanding OTA walk-through

Postby plajjd » Thu Aug 16, 2018 6:10 pm

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Not understanding OTA walk-through

Postby kolban » Thu Aug 16, 2018 6:16 pm

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Not understanding OTA walk-through

Postby fly135 » Thu Aug 16, 2018 6:21 pm

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.

IsaacJones
Posts: 2
Joined: Wed Aug 15, 2018 7:39 pm

Re: Not understanding OTA walk-through

Postby IsaacJones » Fri Aug 17, 2018 1:57 pm

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?

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Not understanding OTA walk-through

Postby fly135 » Sat Aug 18, 2018 2:22 pm

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? "

Who is online

Users browsing this forum: Bing [Bot] and 104 guests