diff --git a/components/esp_https_ota/include/esp_https_ota.h b/components/esp_https_ota/include/esp_https_ota.h index 2a987ca692..a87ba8df0a 100644 --- a/components/esp_https_ota/include/esp_https_ota.h +++ b/components/esp_https_ota/include/esp_https_ota.h @@ -201,6 +201,21 @@ esp_err_t esp_https_ota_get_img_desc(esp_https_ota_handle_t https_ota_handle, es */ int esp_https_ota_get_image_len_read(esp_https_ota_handle_t https_ota_handle); + +/** +* @brief This function returns OTA image total size. +* +* @note This API should be called after esp_https_ota_begin() has been already called. +* This can be used to create some sort of progress indication +* (in combination with esp_https_ota_get_image_len_read()) +* +* @param[in] https_ota_handle pointer to esp_https_ota_handle_t structure +* +* @return +* - -1 On failure or chunked encoding +* - total bytes of image +*/ +int esp_https_ota_get_image_size(esp_https_ota_handle_t https_ota_handle); #ifdef __cplusplus } #endif diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 49fd436ce8..1e9cdec2cf 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -246,6 +246,10 @@ esp_err_t esp_https_ota_begin(esp_https_ota_config_t *ota_config, esp_https_ota_ goto http_cleanup; } + if (!https_ota_handle->partial_http_download) { + https_ota_handle->image_length = esp_http_client_get_content_length(https_ota_handle->http_client); + } + https_ota_handle->update_partition = NULL; ESP_LOGI(TAG, "Starting OTA..."); https_ota_handle->update_partition = esp_ota_get_next_update_partition(NULL); @@ -521,6 +525,18 @@ int esp_https_ota_get_image_len_read(esp_https_ota_handle_t https_ota_handle) return handle->binary_file_len; } +int esp_https_ota_get_image_size(esp_https_ota_handle_t https_ota_handle) +{ + esp_https_ota_t *handle = (esp_https_ota_t *)https_ota_handle; + if (handle == NULL) { + return -1; + } + if (handle->state < ESP_HTTPS_OTA_BEGIN) { + return -1; + } + return handle->image_length; +} + esp_err_t esp_https_ota(const esp_http_client_config_t *config) { if (!config) {