ota.cpp: bugfix
This commit is contained in:
parent
3aa8a88d3a
commit
26ea8621c2
25
src/ota.cpp
25
src/ota.cpp
@ -75,6 +75,7 @@ void start_ota_update() {
|
|||||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||||
|
|
||||||
int i = WIFI_MAX_TRY, j = OTA_MAX_TRY;
|
int i = WIFI_MAX_TRY, j = OTA_MAX_TRY;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
ESP_LOGI(TAG, "Trying to connect to %s", WIFI_SSID);
|
ESP_LOGI(TAG, "Trying to connect to %s", WIFI_SSID);
|
||||||
@ -82,26 +83,29 @@ void start_ota_update() {
|
|||||||
// we now have wifi connection and try to do an OTA over wifi update
|
// we now have wifi connection and try to do an OTA over wifi update
|
||||||
ESP_LOGI(TAG, "Connected to %s", WIFI_SSID);
|
ESP_LOGI(TAG, "Connected to %s", WIFI_SSID);
|
||||||
display(1, "OK", "WiFi connected");
|
display(1, "OK", "WiFi connected");
|
||||||
// do a number of tries limited by OTA_MAX_TRY
|
// do a number of tries to update firmware limited by OTA_MAX_TRY
|
||||||
while (j--) {
|
while ( j--) {
|
||||||
ESP_LOGI(TAG,
|
ESP_LOGI(TAG,
|
||||||
"Starting OTA update, attempt %u of %u. This will take some "
|
"Starting OTA update, attempt %u of %u. This will take some "
|
||||||
"time to complete...",
|
"time to complete...",
|
||||||
OTA_MAX_TRY - j, OTA_MAX_TRY);
|
OTA_MAX_TRY - j, OTA_MAX_TRY);
|
||||||
if (do_ota_update())
|
ret = do_ota_update();
|
||||||
goto end;
|
if (ret)
|
||||||
|
goto end; // update successful
|
||||||
}
|
}
|
||||||
} else {
|
goto end; // update not successful
|
||||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Could not connect to %s, rebooting.", WIFI_SSID);
|
// wifi did not connect
|
||||||
|
ESP_LOGI(TAG, "Could not connect to %s", WIFI_SSID);
|
||||||
display(1, " E", "no WiFi connect");
|
display(1, " E", "no WiFi connect");
|
||||||
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
switch_LED(LED_OFF);
|
switch_LED(LED_OFF);
|
||||||
|
ESP_LOGI(TAG, "Rebooting to runmode using %s firmware",
|
||||||
|
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();
|
||||||
@ -281,13 +285,12 @@ bool do_ota_update() {
|
|||||||
|
|
||||||
finished:
|
finished:
|
||||||
client.stop();
|
client.stop();
|
||||||
ESP_LOGI(TAG, "OTA update completed. Rebooting to runmode with new version.");
|
ESP_LOGI(TAG, "OTA update completed.");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
failure:
|
failure:
|
||||||
client.stop();
|
client.stop();
|
||||||
ESP_LOGI(TAG,
|
ESP_LOGI(TAG, "OTA update failed.");
|
||||||
"OTA update failed. Rebooting to runmode with current version.");
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} // do_ota_update
|
} // do_ota_update
|
||||||
|
Loading…
Reference in New Issue
Block a user