Merge branch 'feature/handle_ota_image_not_modified_case' into 'master'

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

Closes IDFGH-14016

See merge request espressif/esp-idf!34808
pull/14997/head
Mahavir Jain 2024-12-05 13:50:22 +08:00
commit 3029a4b97b
4 zmienionych plików z 18 dodań i 1 usunięć

Wyświetl plik

@ -656,6 +656,9 @@ static const esp_err_msg_t esp_err_msg_table[] = {
# endif
# ifdef ESP_ERR_HTTP_CONNECTION_CLOSED
ERR_TBL_IT(ESP_ERR_HTTP_CONNECTION_CLOSED), /* 28680 0x7008 Read FIN from peer and the connection closed */
# endif
# ifdef ESP_ERR_HTTP_NOT_MODIFIED
ERR_TBL_IT(ESP_ERR_HTTP_NOT_MODIFIED), /* 28681 0x7009 HTTP 304 Not Modified, no update available */
# endif
// components/esp-tls/esp_tls_errors.h
# ifdef ESP_ERR_ESP_TLS_BASE

Wyświetl plik

@ -208,6 +208,7 @@ typedef enum {
HttpStatus_MovedPermanently = 301,
HttpStatus_Found = 302,
HttpStatus_SeeOther = 303,
HttpStatus_NotModified = 304,
HttpStatus_TemporaryRedirect = 307,
HttpStatus_PermanentRedirect = 308,
@ -230,6 +231,7 @@ typedef enum {
#define ESP_ERR_HTTP_CONNECTING (ESP_ERR_HTTP_BASE + 6) /*!< HTTP connection hasn't been established yet */
#define ESP_ERR_HTTP_EAGAIN (ESP_ERR_HTTP_BASE + 7) /*!< Mapping of errno EAGAIN to esp_err_t */
#define ESP_ERR_HTTP_CONNECTION_CLOSED (ESP_ERR_HTTP_BASE + 8) /*!< Read FIN from peer and the connection closed */
#define ESP_ERR_HTTP_NOT_MODIFIED (ESP_ERR_HTTP_BASE + 9) /*!< HTTP 304 Not Modified, no update available */
/**
* @brief Start a HTTP session

Wyświetl plik

@ -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.
*/

Wyświetl plik

@ -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;
}