How to find the image size for OTA

chadpham75
Posts: 39
Joined: Thu Sep 12, 2019 11:39 am

How to find the image size for OTA

Postby chadpham75 » Thu Jan 16, 2020 9:34 am

Hi all,
Do any of you know how can find the download image's size at the time we check for the image's description at the beginning of the OTA? I would like to show the status of the download by using the percentage of the image's size since I do know the image_len_read.

chadpham75
Posts: 39
Joined: Thu Sep 12, 2019 11:39 am

Re: How to find the image size for OTA

Postby chadpham75 » Fri Jan 24, 2020 10:33 pm

Anyone? Any suggestion?

ESP_Mahavir
Posts: 31
Joined: Wed Jan 24, 2018 6:51 am

Re: How to find the image size for OTA

Postby ESP_Mahavir » Sat Jan 25, 2020 6:40 am

Following code snippet from `advanced_https_ota_example` should help here:

Code: Select all

    while (1) {
        err = esp_https_ota_perform(https_ota_handle);
        if (err != ESP_ERR_HTTPS_OTA_IN_PROGRESS) {
            break;
        }
        // esp_https_ota_perform returns after every read operation which gives user the ability to
        // monitor the status of OTA upgrade by calling esp_https_ota_get_image_len_read, which gives length of image
        // data read so far.
        ESP_LOGD(TAG, "Image bytes read: %d", esp_https_ota_get_image_len_read(https_ota_handle));
    }
https://github.com/espressif/esp-idf/bl ... #L112-L115

boarchuz
Posts: 257
Joined: Tue Aug 21, 2018 5:28 am

Re: How to find the image size for OTA

Postby boarchuz » Sat Jan 25, 2020 12:08 pm

I think what you want is the total binary size, so that you can determine the progress, eg. image_len_read / total_size * 100 = x%.
Assuming you're downloading the firmware, most servers will automatically set the Content-Length header, otherwise you'll have to implement it on the server some other way (eg. with a custom header, or a separate query for metadata, or embed metadata with the binary, etc).

chadpham75
Posts: 39
Joined: Thu Sep 12, 2019 11:39 am

Re: How to find the image size for OTA

Postby chadpham75 » Sun Jan 26, 2020 2:52 am

@ESP_Mahavir,
Thank you for the suggestion, but the snippet you suggest only give me the number of byte the successfully download and write to flash each esp_https_ota_perform() function call. It won't help what I am looking for.
What I am looking for is the whole image's size before the download is actually going on. I dig deep inside the advanced_https_ota_example, and there is nothing actually help. All the content_length from the responds return -1 or 0.
@boarchuz,
You are correct on what I am looking for. Do you know from the ota examples guide from esp like this https://github.com/espressif/esp-idf/tr ... system/ota, how can we set the content_length? All I got from the reading the content_length is -1.

chadpham75
Posts: 39
Joined: Thu Sep 12, 2019 11:39 am

Re: How to find the image size for OTA

Postby chadpham75 » Tue Jan 28, 2020 5:59 am

Hi all,
If you have a chance go over this thread, please simply just leave a message either "me too" or "+1". I am just curiously how many people are looking for the same solution/method. I can see the number of people who read this post increasingly but nothing/no comment. May be if may be too many people looking the same thing, we may have a better chance foe ESP support.
Thank you for reading this.

boarchuz
Posts: 257
Joined: Tue Aug 21, 2018 5:28 am

Re: How to find the image size for OTA

Postby boarchuz » Tue Jan 28, 2020 9:06 am

You're barking up the wrong tree. This has nothing to do with the functionality of the ESP32. There's no way to magically determine the total size if the server isn't providing that information.

So you'll need to configure your server:
Most servers will automatically set the Content-Length header (I'd suggest investigating this), otherwise you'll have to implement it on the server some other way (eg. with a custom header, or a separate query for metadata, or embed metadata with the binary, etc).
If that's not possible you might consider using the size of the current app (which your ESP32 can determine independently) instead. The size is unlikely to change dramatically between versions so this will be reasonably accurate for the purposes of a visual indicator.

chadpham75
Posts: 39
Joined: Thu Sep 12, 2019 11:39 am

Re: How to find the image size for OTA

Postby chadpham75 » Tue Jan 28, 2020 7:18 pm

@boarchuz,
Thank you. I already made the decision to have the server's team help in this sizeof thing. I just try to see if there is api provide by ESP to support this, but I understand now it is not their responsibilities.

Who is online

Users browsing this forum: Google [Bot], zliudr and 45 guests