feat(esp_htttps_ota): handle case if server retured 304 not_modified during ota

This commit handles case for response code 304 (NOT_MODIFIED) during ota.

Closes https://github.com/espressif/esp-idf/issues/14839
This commit is contained in:
nilesh.kale
2024-11-11 14:24:00 +05:30
committed by Nilesh Kale
parent 1b44d4df3b
commit 0733de565f
4 changed files with 18 additions and 1 deletions

View File

@@ -103,6 +103,7 @@ typedef struct {
* - ESP_ERR_OTA_VALIDATE_FAILED: Invalid app image
* - ESP_ERR_NO_MEM: Cannot allocate memory for OTA operation.
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
* - ESP_ERR_HTTP_NOT_MODIFIED: OTA image is not modified on server side
* - For other return codes, refer OTA documentation in esp-idf's app_update component.
*/
esp_err_t esp_https_ota(const esp_https_ota_config_t *ota_config);
@@ -129,6 +130,7 @@ esp_err_t esp_https_ota(const esp_https_ota_config_t *ota_config);
* - ESP_OK: HTTPS OTA Firmware upgrade context initialised and HTTPS connection established
* - ESP_FAIL: For generic failure.
* - ESP_ERR_INVALID_ARG: Invalid argument (missing/incorrect config, certificate, etc.)
* - ESP_ERR_HTTP_NOT_MODIFIED: OTA image is not modified on server side
* - For other return codes, refer documentation in app_update component and esp_http_client
* component in esp-idf.
*/

View File

@@ -97,12 +97,16 @@ static bool process_again(int status_code)
static esp_err_t _http_handle_response_code(esp_https_ota_t *https_ota_handle, int status_code)
{
esp_err_t err;
if (redirection_required(status_code)) {
err = esp_http_client_set_redirection(https_ota_handle->http_client);
if (err != ESP_OK) {
ESP_LOGE(TAG, "URL redirection Failed");
return err;
}
} else if (status_code == HttpStatus_NotModified) {
ESP_LOGI(TAG, "OTA image not modified since last request (status code: %d)", status_code);
return ESP_ERR_HTTP_NOT_MODIFIED;
} else if (status_code == HttpStatus_Unauthorized) {
if (https_ota_handle->max_authorization_retries == 0) {
ESP_LOGE(TAG, "Reached max_authorization_retries (%d)", status_code);
@@ -357,7 +361,9 @@ esp_err_t esp_https_ota_begin(const esp_https_ota_config_t *ota_config, esp_http
err = _http_connect(https_ota_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to establish HTTP connection");
if (err != ESP_ERR_HTTP_NOT_MODIFIED) {
ESP_LOGE(TAG, "Failed to establish HTTP connection");
}
goto http_cleanup;
} else {
esp_https_ota_dispatch_event(ESP_HTTPS_OTA_CONNECTED, NULL, 0);
@@ -820,6 +826,10 @@ esp_err_t esp_https_ota(const esp_https_ota_config_t *ota_config)
esp_https_ota_handle_t https_ota_handle = NULL;
esp_err_t err = esp_https_ota_begin(ota_config, &https_ota_handle);
if (err != ESP_OK) {
return err;
}
if (https_ota_handle == NULL) {
return ESP_FAIL;
}