diff --git a/esphome/components/ota/ota_backend_esp_idf.cpp b/esphome/components/ota/ota_backend_esp_idf.cpp index 336b3798d9..167f8c059b 100644 --- a/esphome/components/ota/ota_backend_esp_idf.cpp +++ b/esphome/components/ota/ota_backend_esp_idf.cpp @@ -49,7 +49,7 @@ OTAResponseTypes IDFOTABackend::end() { this->md5_.calculate(); if (!this->md5_.equals_hex(this->expected_bin_md5_)) { this->abort(); - return OTA_RESPONSE_ERROR_UPDATE_END; + return OTA_RESPONSE_ERROR_MD5_MISMATCH; } esp_err_t err = esp_ota_end(this->update_handle_); this->update_handle_ = 0; diff --git a/esphome/components/ota/ota_component.cpp b/esphome/components/ota/ota_component.cpp index fa2605d589..25c9f2e912 100644 --- a/esphome/components/ota/ota_component.cpp +++ b/esphome/components/ota/ota_component.cpp @@ -296,7 +296,7 @@ void OTAComponent::handle_() { error_code = backend->write(buf, read); if (error_code != OTA_RESPONSE_OK) { - ESP_LOGW(TAG, "Error writing binary data to flash!"); + ESP_LOGW(TAG, "Error writing binary data to flash!, error_code: %d", error_code); goto error; // NOLINT(cppcoreguidelines-avoid-goto) } total += read; @@ -321,7 +321,7 @@ void OTAComponent::handle_() { error_code = backend->end(); if (error_code != OTA_RESPONSE_OK) { - ESP_LOGW(TAG, "Error ending OTA!"); + ESP_LOGW(TAG, "Error ending OTA!, error_code: %d", error_code); goto error; // NOLINT(cppcoreguidelines-avoid-goto) } diff --git a/esphome/components/ota/ota_component.h b/esphome/components/ota/ota_component.h index 5647d52eeb..d178805168 100644 --- a/esphome/components/ota/ota_component.h +++ b/esphome/components/ota/ota_component.h @@ -32,6 +32,7 @@ enum OTAResponseTypes { OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136, OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137, OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION = 138, + OTA_RESPONSE_ERROR_MD5_MISMATCH = 139, OTA_RESPONSE_ERROR_UNKNOWN = 255, }; diff --git a/esphome/espota2.py b/esphome/espota2.py index 76f3b917c9..98d6d3a0d9 100644 --- a/esphome/espota2.py +++ b/esphome/espota2.py @@ -30,6 +30,8 @@ RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG = 134 RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG = 135 RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136 RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137 +RESPONSE_ERROR_NO_UPDATE_PARTITION = 138 +RESPONSE_ERROR_MD5_MISMATCH = 139 RESPONSE_ERROR_UNKNOWN = 255 OTA_VERSION_1_0 = 1 @@ -150,6 +152,16 @@ def check_error(data, expect): "Error: The OTA partition on the ESP is too small. ESPHome needs to resize " "this partition, please flash over USB." ) + if dat == RESPONSE_ERROR_NO_UPDATE_PARTITION: + raise OTAError( + "Error: The OTA partition on the ESP couldn't be found. ESPHome needs to create " + "this partition, please flash over USB." + ) + if dat == RESPONSE_ERROR_MD5_MISMATCH: + raise OTAError( + "Error: Application MD5 code mismatch. Please try again " + "or flash over USB with a good quality cable." + ) if dat == RESPONSE_ERROR_UNKNOWN: raise OTAError("Unknown error from ESP") if not isinstance(expect, (list, tuple)):