From b197ee8a8058634fa8671d4cacbb551bf86ed3e3 Mon Sep 17 00:00:00 2001 From: Rick Watson Date: Tue, 23 Oct 2018 13:55:25 +0100 Subject: [PATCH] calculate elapsed time rather than storing next fire time - avoids overflow issues --- src/APSettingsService.cpp | 16 +++++++++------- src/APSettingsService.h | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/APSettingsService.cpp b/src/APSettingsService.cpp index 4aecb41..d293ad1 100644 --- a/src/APSettingsService.cpp +++ b/src/APSettingsService.cpp @@ -1,16 +1,18 @@ #include APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs) : SettingsService(server, fs, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) { + onConfigUpdated(); } APSettingsService::~APSettingsService() {} void APSettingsService::loop() { - unsigned long now = millis(); - if (_manageAtMillis <= now){ - manageAP(); - _manageAtMillis = now + MANAGE_NETWORK_DELAY; - } + unsigned long currentMillis = millis(); + unsigned long manageElapsed = (unsigned long)(currentMillis - _lastManaged); + if (manageElapsed >= MANAGE_NETWORK_DELAY){ + _lastManaged = currentMillis; + manageAP(); + } handleDNS(); } @@ -78,5 +80,5 @@ void APSettingsService::writeToJsonObject(JsonObject& root) { } void APSettingsService::onConfigUpdated() { - _manageAtMillis = 0; -} + _lastManaged = millis() - MANAGE_NETWORK_DELAY; +} \ No newline at end of file diff --git a/src/APSettingsService.h b/src/APSettingsService.h index 63aaf9c..6f59ce3 100644 --- a/src/APSettingsService.h +++ b/src/APSettingsService.h @@ -42,7 +42,7 @@ class APSettingsService : public SettingsService { String _password; // for the mangement delay loop - unsigned long _manageAtMillis; + unsigned long _lastManaged; // for the captive portal DNSServer *_dnsServer; @@ -54,4 +54,4 @@ class APSettingsService : public SettingsService { }; -#endif // end APSettingsConfig_h +#endif // end APSettingsConfig_h \ No newline at end of file