OTA wifi stability improvement
This commit is contained in:
parent
4033c59191
commit
2d0f9c3c13
@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
|
||||
|
||||
[common]
|
||||
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
||||
release_version = 1.6.96
|
||||
release_version = 1.6.97
|
||||
; 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
|
||||
debug_level = 0
|
||||
|
12
src/ota.cpp
12
src/ota.cpp
@ -71,25 +71,27 @@ void start_ota_update() {
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
|
||||
int i = WIFI_MAX_TRY, j = OTA_MAX_TRY;
|
||||
uint8_t i = WIFI_MAX_TRY;
|
||||
int ret = 1; // 0 = finished, 1 = retry, -1 = abort
|
||||
|
||||
ESP_LOGI(TAG, "Trying to connect to %s", WIFI_SSID);
|
||||
|
||||
while (i--) {
|
||||
ESP_LOGI(TAG, "Trying to connect to %s, attempt %u of %u", WIFI_SSID,
|
||||
WIFI_MAX_TRY - i, WIFI_MAX_TRY);
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS); // wait for stable connect
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
// we now have wifi connection and try to do an OTA over wifi update
|
||||
ESP_LOGI(TAG, "Connected to %s", WIFI_SSID);
|
||||
display(1, "OK", "WiFi connected");
|
||||
// do a number of tries to update firmware limited by OTA_MAX_TRY
|
||||
uint8_t j = OTA_MAX_TRY;
|
||||
while ((j--) && (ret > 0)) {
|
||||
ESP_LOGI(TAG, "Starting OTA update, attempt %u of %u", OTA_MAX_TRY - j,
|
||||
OTA_MAX_TRY);
|
||||
ret = do_ota_update();
|
||||
}
|
||||
goto end;
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
goto end; // OTA update finished or OTA max attemps reached
|
||||
}
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
WiFi.reconnect();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user