Ver código fonte

OTA: Fixed OTA with chunked servers

If esp_http_client_read returns 0, errno check is performed if complete data is not received.
Shubham Kulkarni 6 anos atrás
pai
commit
9df632482c
1 arquivos alterados com 11 adições e 7 exclusões
  1. 11 7
      components/esp_https_ota/src/esp_https_ota.c

+ 11 - 7
components/esp_https_ota/src/esp_https_ota.c

@@ -295,18 +295,22 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle)
                                              handle->ota_upgrade_buf,
                                              handle->ota_upgrade_buf_size);
             if (data_read == 0) {
+                /*
+                 *  esp_https_ota_is_complete_data_received is added to check whether
+                 *  complete image is received.
+                 */
+                bool is_recv_complete = esp_https_ota_is_complete_data_received(https_ota_handle);
                 /*
                  * As esp_http_client_read never returns negative error code, we rely on
-                 * `errno` to check for underlying transport connectivity closure if any
+                 * `errno` to check for underlying transport connectivity closure if any.
+                 * Incase the complete data has not been received but the server has sent
+                 * an ENOTCONN or ECONNRESET, failure is returned. We close with success
+                 * if complete data has been received.
                  */
-                if (errno == ENOTCONN || errno == ECONNRESET) {
+                if ((errno == ENOTCONN || errno == ECONNRESET) && !is_recv_complete) {
                     ESP_LOGE(TAG, "Connection closed, errno = %d", errno);
                     return ESP_FAIL;
-                }
-                /*  esp_https_ota_is_complete_data_received is added to check whether
-                    complete image is received.
-                */
-                if (!esp_https_ota_is_complete_data_received(https_ota_handle)) {
+                } else if (!is_recv_complete) {
                     return ESP_ERR_HTTPS_OTA_IN_PROGRESS;
                 }
                 ESP_LOGI(TAG, "Connection closed");