From 70d4414eeb7a8e09604df7e98212c9923ee8c04d Mon Sep 17 00:00:00 2001 From: "nilesh.kale" Date: Fri, 30 Aug 2024 11:29:05 +0530 Subject: [PATCH] feat(esp_https_ota): added API to get last status code logged from http resonse Closes https://github.com/espressif/esp-idf/issues/14302 --- components/esp_https_ota/include/esp_https_ota.h | 15 +++++++++++++++ components/esp_https_ota/src/esp_https_ota.c | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/components/esp_https_ota/include/esp_https_ota.h b/components/esp_https_ota/include/esp_https_ota.h index fedecb48f2..850d329a05 100644 --- a/components/esp_https_ota/include/esp_https_ota.h +++ b/components/esp_https_ota/include/esp_https_ota.h @@ -239,6 +239,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 the HTTP status code of the last HTTP response. + * + * @note This API should be called only after esp_https_ota_begin() has been called. + * This can be used to check the HTTP status code of the OTA download process. + * + * @param[in] https_ota_handle pointer to esp_https_ota_handle_t structure + * + * @return + * - -1 On failure + * - HTTP status code + */ +int esp_https_ota_get_status_code(esp_https_ota_handle_t https_ota_handle); + + /** * @brief This function returns OTA image total size. * diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 65165071ad..f21eabced5 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -724,6 +724,15 @@ esp_err_t esp_https_ota_abort(esp_https_ota_handle_t https_ota_handle) return err; } +int esp_https_ota_get_status_code(esp_https_ota_handle_t https_ota_handle) +{ + esp_https_ota_t *handle = (esp_https_ota_t *) https_ota_handle; + if (handle == NULL || handle->http_client == NULL) { + return -1; + } + return esp_http_client_get_status_code(handle->http_client); +} + int esp_https_ota_get_image_len_read(esp_https_ota_handle_t https_ota_handle) { esp_https_ota_t *handle = (esp_https_ota_t *)https_ota_handle;