ota.cpp: bugfix

This commit is contained in:
Klaus K Wilting 2018-09-19 01:35:20 +02:00
parent d80d1e24e9
commit 7b6c2f1090
2 changed files with 13 additions and 7 deletions

View File

@ -25,8 +25,8 @@ env_default = generic
description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around.
[common] [common]
; for release_version use max.10 chars total, use any decimal format like "a.b.c" ; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.4.34 release_version = 1.4.35
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 0 debug_level = 0

View File

@ -112,7 +112,7 @@ void processOTAUpdate(const String &version) {
} }
} }
ESP_LOGI(TAG, "Requesting %s", firmwarePath); ESP_LOGI(TAG, "Requesting %s", firmwarePath.c_str());
client.print(String("GET ") + firmwarePath + " HTTP/1.1\r\n"); client.print(String("GET ") + firmwarePath + " HTTP/1.1\r\n");
client.print(String("Host: ") + currentHost + "\r\n"); client.print(String("Host: ") + currentHost + "\r\n");
@ -162,7 +162,6 @@ void processOTAUpdate(const String &version) {
currentHost = newUrl.substring(0, newUrl.indexOf('/')); currentHost = newUrl.substring(0, newUrl.indexOf('/'));
newUrl.remove(newUrl.indexOf(currentHost), currentHost.length()); newUrl.remove(newUrl.indexOf(currentHost), currentHost.length());
firmwarePath = newUrl; firmwarePath = newUrl;
ESP_LOGI(TAG, "firmwarePath: %s", firmwarePath.c_str());
continue; continue;
} }
@ -196,7 +195,7 @@ void processOTAUpdate(const String &version) {
ESP_LOGI(TAG, ESP_LOGI(TAG,
"Starting OTA update, attempt %d of %d. This will take some " "Starting OTA update, attempt %d of %d. This will take some "
"time to complete...", "time to complete...",
i, FLASH_MAX_TRY); FLASH_MAX_TRY - i, FLASH_MAX_TRY);
written = Update.writeStream(client); written = Update.writeStream(client);
@ -213,7 +212,10 @@ void processOTAUpdate(const String &version) {
if (Update.end()) { if (Update.end()) {
if (Update.isFinished()) { if (Update.isFinished()) {
ESP_LOGI(TAG, "OTA update completed. Rebooting to runmode."); ESP_LOGI(
TAG,
"OTA update completed. Rebooting to runmode with new version.");
client.stop();
ESP.restart(); ESP.restart();
} else { } else {
ESP_LOGI(TAG, "Something went wrong! OTA update hasn't been finished " ESP_LOGI(TAG, "Something went wrong! OTA update hasn't been finished "
@ -232,6 +234,10 @@ void processOTAUpdate(const String &version) {
"There was no valid content in the response from the OTA server!"); "There was no valid content in the response from the OTA server!");
client.flush(); client.flush();
} }
ESP_LOGI(TAG,
"OTA update failed. Rebooting to runmode with current version.");
client.stop();
ESP.restart();
} }
// helper function to compare two versions. Returns 1 if v2 is // helper function to compare two versions. Returns 1 if v2 is