ota.cpp: shortened log texts

This commit is contained in:
Klaus K Wilting 2018-11-04 21:02:37 +01:00
parent c061f3f586
commit 4a9db7a4c0

View File

@ -85,10 +85,8 @@ void start_ota_update() {
display(1, "OK", "WiFi connected"); display(1, "OK", "WiFi connected");
// do a number of tries to update firmware limited by OTA_MAX_TRY // do a number of tries to update firmware limited by OTA_MAX_TRY
while ((j--) && (!ret)) { while ((j--) && (!ret)) {
ESP_LOGI(TAG, ESP_LOGI(TAG, "Starting OTA update, attempt %u of %u", OTA_MAX_TRY - j,
"Starting OTA update, attempt %u of %u. This will take some " OTA_MAX_TRY);
"time to complete...",
OTA_MAX_TRY - j, OTA_MAX_TRY);
ret = do_ota_update(); ret = do_ota_update();
} }
goto end; goto end;
@ -102,8 +100,7 @@ void start_ota_update() {
end: end:
switch_LED(LED_OFF); switch_LED(LED_OFF);
ESP_LOGI(TAG, "Rebooting to runmode using %s firmware", ESP_LOGI(TAG, "Rebooting to %s firmware", ret ? "new" : "current");
ret ? "new" : "current");
display(5, "**", ""); // mark line rebooting display(5, "**", ""); // mark line rebooting
vTaskDelay(5000 / portTICK_PERIOD_MS); vTaskDelay(5000 / portTICK_PERIOD_MS);
ESP.restart(); ESP.restart();
@ -117,29 +114,26 @@ bool do_ota_update() {
size_t written = 0; size_t written = 0;
// Fetch the latest firmware version // Fetch the latest firmware version
ESP_LOGI(TAG, "Checking latest firmware version on server..."); ESP_LOGI(TAG, "Checking latest firmware version on server");
display(2, "**", "checking version"); display(2, "**", "checking version");
const String latest = bintray.getLatestVersion(); const String latest = bintray.getLatestVersion();
if (latest.length() == 0) { if (latest.length() == 0) {
ESP_LOGI( ESP_LOGI(TAG, "Could not fetch info on latest firmware");
TAG,
"Could not load info about the latest firmware. Rebooting to runmode.");
display(2, " E", "file not found"); display(2, " E", "file not found");
return false; return false;
} else if (version_compare(latest, cfg.version) <= 0) { } else if (version_compare(latest, cfg.version) <= 0) {
ESP_LOGI(TAG, "Current firmware is up to date. Rebooting to runmode."); ESP_LOGI(TAG, "Current firmware is up to date");
display(2, "NO", "no update found"); display(2, "NO", "no update found");
return false; return false;
} }
ESP_LOGI(TAG, "New firmware version v%s available. Downloading...", ESP_LOGI(TAG, "New firmware version v%s available", latest.c_str());
latest.c_str());
display(2, "OK", latest.c_str()); display(2, "OK", latest.c_str());
display(3, "**", ""); display(3, "**", "");
String firmwarePath = bintray.getBinaryPath(latest); String firmwarePath = bintray.getBinaryPath(latest);
if (!firmwarePath.endsWith(".bin")) { if (!firmwarePath.endsWith(".bin")) {
ESP_LOGI(TAG, "Unsupported binary format, OTA update cancelled."); ESP_LOGI(TAG, "Unsupported binary format");
display(3, " E", "file type error"); display(3, " E", "file type error");
return false; return false;
} }
@ -178,7 +172,7 @@ bool do_ota_update() {
unsigned long timeout = millis(); unsigned long timeout = millis();
while (client.available() == 0) { while (client.available() == 0) {
if (millis() - timeout > RESPONSE_TIMEOUT_MS) { if (millis() - timeout > RESPONSE_TIMEOUT_MS) {
ESP_LOGI(TAG, "Client Timeout."); ESP_LOGI(TAG, "Client timeout");
display(3, " E", "client timeout"); display(3, " E", "client timeout");
goto failure; goto failure;
} }
@ -200,11 +194,11 @@ bool do_ota_update() {
"firmware flashing"); "firmware flashing");
redirect = false; redirect = false;
} else if (line.indexOf("302") > 0) { } else if (line.indexOf("302") > 0) {
ESP_LOGI(TAG, "Got 302 status code from server. Redirecting to the " ESP_LOGI(TAG, "Got 302 status code from server. Redirecting to "
"new address"); "new address");
redirect = true; redirect = true;
} else { } else {
ESP_LOGI(TAG, "Could not get a valid firmware url."); ESP_LOGI(TAG, "Could not get firmware download URL");
// Unexptected HTTP response. Retry or skip update? // Unexptected HTTP response. Retry or skip update?
redirect = false; redirect = false;
} }
@ -242,14 +236,13 @@ bool do_ota_update() {
// check whether we have everything for OTA update // check whether we have everything for OTA update
if (!(contentLength && isValidContentType)) { if (!(contentLength && isValidContentType)) {
ESP_LOGI(TAG, ESP_LOGI(TAG, "Invalid OTA server response");
"There was no valid content in the response from the OTA server!");
display(4, " E", "response error"); display(4, " E", "response error");
goto failure; goto failure;
} }
if (!Update.begin(contentLength)) { if (!Update.begin(contentLength)) {
ESP_LOGI(TAG, "There isn't enough space to start OTA update"); ESP_LOGI(TAG, "Not enough space to start OTA update");
display(4, " E", "disk full"); display(4, " E", "disk full");
goto failure; goto failure;
} }
@ -270,7 +263,7 @@ bool do_ota_update() {
snprintf(buf, 17, "%ukB Done!", (uint16_t)(written / 1024)); snprintf(buf, 17, "%ukB Done!", (uint16_t)(written / 1024));
display(4, "OK", buf); display(4, "OK", buf);
} else { } else {
ESP_LOGI(TAG, "Written only %u of %u bytes, OTA update attempt cancelled.", ESP_LOGI(TAG, "Written only %u of %u bytes, OTA update attempt cancelled",
written, contentLength); written, contentLength);
} }
@ -285,12 +278,12 @@ bool do_ota_update() {
finished: finished:
client.stop(); client.stop();
ESP_LOGI(TAG, "OTA update completed."); ESP_LOGI(TAG, "OTA update finished");
return true; return true;
failure: failure:
client.stop(); client.stop();
ESP_LOGI(TAG, "OTA update failed."); ESP_LOGI(TAG, "OTA update failed");
return false; return false;
} // do_ota_update } // do_ota_update