calculate elapsed time rather than storing next fire time - avoids overflow issues

This commit is contained in:
Rick Watson 2018-10-23 13:55:25 +01:00
parent ec829173f9
commit b197ee8a80
2 changed files with 11 additions and 9 deletions

View File

@ -1,15 +1,17 @@
#include <APSettingsService.h>
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){
unsigned long currentMillis = millis();
unsigned long manageElapsed = (unsigned long)(currentMillis - _lastManaged);
if (manageElapsed >= MANAGE_NETWORK_DELAY){
_lastManaged = currentMillis;
manageAP();
_manageAtMillis = now + MANAGE_NETWORK_DELAY;
}
handleDNS();
}
@ -78,5 +80,5 @@ void APSettingsService::writeToJsonObject(JsonObject& root) {
}
void APSettingsService::onConfigUpdated() {
_manageAtMillis = 0;
_lastManaged = millis() - MANAGE_NETWORK_DELAY;
}

View File

@ -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;