diff --git a/Nuki.cpp b/Nuki.cpp index 6a71c38..5dd8ec7 100644 --- a/Nuki.cpp +++ b/Nuki.cpp @@ -42,19 +42,21 @@ void Nuki::update() unsigned long ts = millis(); - if(_lastLockStateUpdateTs == 0 || _lastLockStateUpdateTs + 60000 < ts) + if(_nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs) { - _lastLockStateUpdateTs = ts; + _nextLockStateUpdateTs = ts + 60000; updateKeyTurnerState(); } - if(_lastBatteryReportTs == 0 || _lastBatteryReportTs + 600000 < ts) + if(_nextBatteryReportTs == 0 || ts > _nextBatteryReportTs) { - _lastBatteryReportTs = ts; + _nextBatteryReportTs = ts + 60000 * 30; updateBatteryState(); } if(_nextLockAction != (LockAction)0xff) { _nukiBle.lockAction(_nextLockAction, 0, 0); + _nextLockAction = (LockAction)0xff; + _nextLockStateUpdateTs = ts + 11000; } } diff --git a/Nuki.h b/Nuki.h index 13780a9..8e2e549 100644 --- a/Nuki.h +++ b/Nuki.h @@ -31,7 +31,7 @@ private: BatteryReport _lastBatteryReport; bool _paired = false; - unsigned long _lastLockStateUpdateTs = 0; - unsigned long _lastBatteryReportTs = 0; + unsigned long _nextLockStateUpdateTs = 0; + unsigned long _nextBatteryReportTs = 0; LockAction _nextLockAction = (LockAction)0xff; };