(resolved) OTA and the otadata partition

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(resolved) OTA and the otadata partition

Postby mzimmers » Thu Aug 16, 2018 5:07 pm

Hi all -

I'm getting ready to implement OTA functionality for my app. I've read the docs, and it seems fairly straightforward. I have a few questions, please:

1.do I assume correctly that esp_ota_write() maintains a pointer to the location within the partition that will receive the next block of incoming data? So I just feed it the .bin file a block at a time, and it keeps it in order?
2. I see that the otadata partition contains information about which partition to boot to, but I haven't found any specifics about this. Can someone guide me to the right doc for this?
3. I'm planning on using a TCP socket connection for passing the data; is there any unforeseen reason I can't do this?

Thanks...
Last edited by mzimmers on Thu Nov 15, 2018 6:09 pm, edited 1 time in total.

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

Re: OTA and the otadata partition

Postby kolban » Thu Aug 16, 2018 5:20 pm

It is my understanding that esp_ota_write maintains its state. We perform an esp_ota_begin() to begin the work, multiple esp_ota_write() to write the data and then esp_ota_end() to indicate a conclusion.

The function esp_ota_set_boot_partition() identifies the partition that we desire to boot from on next boot.

The function esp_ota_get_boot_partition() returns the current partition that we will next boot from.

There is no reason a TCP socket couldn't be used to retrieve the image bin file. OTA doesn't care how the data arrives and is passed to esp_ota_write(). Whether that is incoming network, SD micro card read, serial input or some other format ... as long as you get the data and write it, you are good. If something goes wrong when retrieving the data then you would not call esp_ota_set_boot_partition() to change the partition to boot from and it would be as though nothing happened.
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: OTA and the otadata partition

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

Use the esp_https_ota to perform the OTA and it's practically a no effort deal. It's literally 3 lines of source code.

Code: Select all

esp_http_client_config_t client;
client.url = "http://mysite.com/mycode.bin;
int ret = esp_https_ota(&client);
John A

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: OTA and the otadata partition

Postby mzimmers » Thu Aug 16, 2018 6:17 pm

Thanks for the answers, Neal.

John: that's a very interesting idea. How do I control which partition is written to? I don't see any information like that in the esp_http_client_config_t struct (nor would I expect to).

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

Re: OTA and the otadata partition

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

mzimmers wrote:Thanks for the answers, Neal.

John: that's a very interesting idea. How do I control which partition is written to? I don't see any information like that in the esp_http_client_config_t struct (nor would I expect to).
It figures it out all on it's own. I defined two OTA partitions and that code just alternates between them. It decides which is the next partition to write to and set it's bootable afterwards.

If you want to get back to the factory to burn manually, just erase the OTADATA partition.

Code: Select all

$IDF_PATH/components/esptool_py/esptool/esptool.py --port com3 erase_region 0xd000 0x2000
in my parition file...

otadata, data, ota, 0xd000, 0x2000

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

Re: OTA and the otadata partition

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

Also... the esp_https_ota requires https and certificate. You can just comment out the test for it and use http or https without certificate.

Code: Select all

    if (!config->cert_pem) {
        ESP_LOGE(TAG, "Server certificate not found in esp_http_client config");
        //return ESP_FAIL;
    }

...
<snip>
...

    if (esp_http_client_get_transport_type(client) != HTTP_TRANSPORT_OVER_SSL) {
        ESP_LOGE(TAG, "Transport is not over HTTPS");
        //return ESP_FAIL;
    }
Also if the code isn't in your current IDF, just copy it into your components directory and it works.

John A

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: OTA and the otadata partition

Postby mzimmers » Thu Aug 16, 2018 6:35 pm

I didn't quite understand that last part, and upon examination, it doesn't appear that I have any esp_https_ota reference in my IDF. So, what exactly am I supposed to copy?

Thanks...

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

Re: OTA and the otadata partition

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

I'm using IDF ver 3.0.2 release. That version doesn't have the new esp_http_client and esp_https_ota. But I also have the IDF master on my computer. So I went that IDF and copied the esp_http_client and esp_https_ota folders into a components folder local to my project. If you are building with a stable release you could probably put them in the components folder in that release.

In my project I am using open source code from various places, including Kolban's BLE code. I have a components directory that I put in my project directory for open source code not in the IDF. That way I can make sure it's checked in with my project and I verify that all the license files are in place for any code I'm using.

John A

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

Re: OTA and the otadata partition

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

I had OTA in my project before esp_https_ota was available (or knew about it). I used the example OTA project and all the steps regarding figuring out the partition to write to and other things could be figured out from looking at the code. Basically you had to have a lot of code in your project to do OTA. I think the original sample didn't support https, so I had to add that. Now it's 3 lines.

I switched over for two reasons. First, I figured that at some point i would need certificates and 2nd we had trouble with SSL OTAs from AWS failing at some point during the download. So I figured that maybe the esp_https_ota and client could be better. According to tests in a crowded wifi environment I'm getting reports that it is more reliable.

John A

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: OTA and the otadata partition

Postby mzimmers » Mon Oct 01, 2018 9:53 pm

After a few diversions, I'm ready to dig into this.

My partition table is set to "Factory app, two OTA definitions." Is there anything else I need to do before I can start using this?

Who is online

Users browsing this forum: Reenis and 97 guests