From 4874f52d96ec992f80d87cfde7ddfbfa9704a223 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Tue, 22 Sep 2020 15:55:31 +0530 Subject: [PATCH] Update advanced_https_ota_example and native_ota_example to use esp_ota_abort in case of error --- .../main/advanced_https_ota_example.c | 28 +++++++++++-------- .../main/native_ota_example.c | 4 +++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c index a00a281e72..0b9abf1c10 100644 --- a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c +++ b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c @@ -144,21 +144,25 @@ void advanced_ota_example_task(void *pvParameter) if (esp_https_ota_is_complete_data_received(https_ota_handle) != true) { // the OTA image was not completely received and user can customise the response to this situation. ESP_LOGE(TAG, "Complete data was not received."); + } else { + ota_finish_err = esp_https_ota_finish(https_ota_handle); + if ((err == ESP_OK) && (ota_finish_err == ESP_OK)) { + ESP_LOGI(TAG, "ESP_HTTPS_OTA upgrade successful. Rebooting ..."); + vTaskDelay(1000 / portTICK_PERIOD_MS); + esp_restart(); + } else { + if (ota_finish_err == ESP_ERR_OTA_VALIDATE_FAILED) { + ESP_LOGE(TAG, "Image validation failed, image is corrupted"); + } + ESP_LOGE(TAG, "ESP_HTTPS_OTA upgrade failed 0x%x", ota_finish_err); + vTaskDelete(NULL); + } } ota_end: - ota_finish_err = esp_https_ota_finish(https_ota_handle); - if ((err == ESP_OK) && (ota_finish_err == ESP_OK)) { - ESP_LOGI(TAG, "ESP_HTTPS_OTA upgrade successful. Rebooting ..."); - vTaskDelay(1000 / portTICK_PERIOD_MS); - esp_restart(); - } else { - if (ota_finish_err == ESP_ERR_OTA_VALIDATE_FAILED) { - ESP_LOGE(TAG, "Image validation failed, image is corrupted"); - } - ESP_LOGE(TAG, "ESP_HTTPS_OTA upgrade failed %d", ota_finish_err); - vTaskDelete(NULL); - } + esp_https_ota_abort(https_ota_handle); + ESP_LOGE(TAG, "ESP_HTTPS_OTA upgrade failed"); + vTaskDelete(NULL); } void app_main(void) diff --git a/examples/system/ota/native_ota_example/main/native_ota_example.c b/examples/system/ota/native_ota_example/main/native_ota_example.c index a81cf9d7a2..6da57f3140 100644 --- a/examples/system/ota/native_ota_example/main/native_ota_example.c +++ b/examples/system/ota/native_ota_example/main/native_ota_example.c @@ -187,18 +187,21 @@ static void ota_example_task(void *pvParameter) if (err != ESP_OK) { ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); http_cleanup(client); + esp_ota_abort(update_handle); task_fatal_error(); } ESP_LOGI(TAG, "esp_ota_begin succeeded"); } else { ESP_LOGE(TAG, "received package is not fit len"); http_cleanup(client); + esp_ota_abort(update_handle); task_fatal_error(); } } err = esp_ota_write( update_handle, (const void *)ota_write_data, data_read); if (err != ESP_OK) { http_cleanup(client); + esp_ota_abort(update_handle); task_fatal_error(); } binary_file_length += data_read; @@ -222,6 +225,7 @@ static void ota_example_task(void *pvParameter) if (esp_http_client_is_complete_data_received(client) != true) { ESP_LOGE(TAG, "Error in receiving complete file"); http_cleanup(client); + esp_ota_abort(update_handle); task_fatal_error(); }