Improve OTA error messages adding return codes (#3698)

This commit is contained in:
Ignacio Hernandez-Ros 2022-08-16 11:51:05 +02:00 committed by GitHub
parent 1a524a5a50
commit df6830110d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View file

@ -49,7 +49,7 @@ OTAResponseTypes IDFOTABackend::end() {
this->md5_.calculate(); this->md5_.calculate();
if (!this->md5_.equals_hex(this->expected_bin_md5_)) { if (!this->md5_.equals_hex(this->expected_bin_md5_)) {
this->abort(); this->abort();
return OTA_RESPONSE_ERROR_UPDATE_END; return OTA_RESPONSE_ERROR_MD5_MISMATCH;
} }
esp_err_t err = esp_ota_end(this->update_handle_); esp_err_t err = esp_ota_end(this->update_handle_);
this->update_handle_ = 0; this->update_handle_ = 0;

View file

@ -296,7 +296,7 @@ void OTAComponent::handle_() {
error_code = backend->write(buf, read); error_code = backend->write(buf, read);
if (error_code != OTA_RESPONSE_OK) { 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) goto error; // NOLINT(cppcoreguidelines-avoid-goto)
} }
total += read; total += read;
@ -321,7 +321,7 @@ void OTAComponent::handle_() {
error_code = backend->end(); error_code = backend->end();
if (error_code != OTA_RESPONSE_OK) { 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) goto error; // NOLINT(cppcoreguidelines-avoid-goto)
} }

View file

@ -32,6 +32,7 @@ enum OTAResponseTypes {
OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136, OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136,
OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137, OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137,
OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION = 138, OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION = 138,
OTA_RESPONSE_ERROR_MD5_MISMATCH = 139,
OTA_RESPONSE_ERROR_UNKNOWN = 255, OTA_RESPONSE_ERROR_UNKNOWN = 255,
}; };

View file

@ -30,6 +30,8 @@ RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG = 134
RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG = 135 RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG = 135
RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136 RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136
RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137 RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137
RESPONSE_ERROR_NO_UPDATE_PARTITION = 138
RESPONSE_ERROR_MD5_MISMATCH = 139
RESPONSE_ERROR_UNKNOWN = 255 RESPONSE_ERROR_UNKNOWN = 255
OTA_VERSION_1_0 = 1 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 " "Error: The OTA partition on the ESP is too small. ESPHome needs to resize "
"this partition, please flash over USB." "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: if dat == RESPONSE_ERROR_UNKNOWN:
raise OTAError("Unknown error from ESP") raise OTAError("Unknown error from ESP")
if not isinstance(expect, (list, tuple)): if not isinstance(expect, (list, tuple)):