From 03a1fc0e21e41f0cf581154b0521fefbf2f9edcd Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 4 Nov 2020 00:39:16 +0100 Subject: [PATCH] optimize OTA handling --- src/esp_clock.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index d132a5b..6849470 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -4,6 +4,8 @@ #include "ntp_time.h" #include "display.h" +#define STAY_CONNECTED_FOR_MINS(min) (min*60) + int currentHour = -1; time_t timeAtStartup; @@ -22,9 +24,7 @@ void setup() { timeAtStartup = updateTime(); } -void loop() { - ArduinoOTA.handle(); - +void loop() { if ((currentHour != hour())) { wifi.reconnect(); wifi.printStatus(); @@ -33,8 +33,11 @@ void loop() { } currentHour = hour(); } - if (WiFi.status() == WL_CONNECTED && difftime(now(), timeAtStartup) > 60) { - wifi.disconnect(); + if (WiFi.status() == WL_CONNECTED) { + ArduinoOTA.handle(); + if (difftime(now(), timeAtStartup) > STAY_CONNECTED_FOR_MINS(1)) { + wifi.disconnect(); + } } displayTime(); displayColon(true);