diff --git a/CMakeLists.txt b/CMakeLists.txt index f07347e..7b9bf96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ file(GLOB SRCFILES lib/nuki_ble/src/NukiBle.cpp lib/nuki_ble/src/NukiConstants.h lib/nuki_ble/src/NukiUtills.h + lib/nuki_ble/src/BleScanner.cpp include_directories(Lib/PubSubClient) lib/pubsubclient/src/PubSubClient.cpp ) diff --git a/Nuki.cpp b/Nuki.cpp index d5f37d6..b54f65f 100644 --- a/Nuki.cpp +++ b/Nuki.cpp @@ -37,6 +37,8 @@ void Nuki::initialize() _preferences->putInt(preference_query_interval_battery, _intervalBattery); } + _nukiBle.setEventHandler(this); + Serial.print(F("Lock state interval: ")); Serial.print(_intervalLockstate); Serial.print(F("| Battery interval: ")); @@ -63,8 +65,9 @@ void Nuki::update() unsigned long ts = millis(); - if(_nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs) + if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs) { + _statusUpdated = false; _nextLockStateUpdateTs = ts + _intervalLockstate * 1000; updateKeyTurnerState(); } @@ -78,6 +81,7 @@ void Nuki::update() _nukiBle.lockAction(_nextLockAction, 0, 0); _nextLockAction = (LockAction)0xff; } + _nukiBle.update(); } void Nuki::updateKeyTurnerState() @@ -94,9 +98,9 @@ void Nuki::updateKeyTurnerState() if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState) { _network->publishKeyTurnerState(lockStateStr, triggerStr, completionStatusStr); - Serial.print(F("Nuki lock state: ")); - Serial.println(lockStateStr); } + Serial.print(F("Nuki lock state: ")); + Serial.println(lockStateStr); memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(KeyTurnerState)); } @@ -244,7 +248,6 @@ LockAction Nuki::lockActionToEnum(const char *str) return (LockAction)0xff; } - void Nuki::onLockActionReceived(const char *value) { nukiInst->_nextLockAction = nukiInst->lockActionToEnum(value); @@ -256,3 +259,12 @@ const bool Nuki::isPaired() { return _paired; } + +void Nuki::notify(NukiEventType eventType) +{ + if(eventType == NukiEventType::KeyTurnerStatusUpdated) + { +// Serial.println("SUP2"); + _statusUpdated = true; + } +} diff --git a/Nuki.h b/Nuki.h index 576ab8c..a93d478 100644 --- a/Nuki.h +++ b/Nuki.h @@ -4,7 +4,7 @@ #include "NukiConstants.h" #include "Network.h" -class Nuki +class Nuki : public NukiSmartlockEventHandler { public: Nuki(const std::string& name, uint32_t id, Network* network, Preferences* preferences); @@ -14,6 +14,8 @@ public: const bool isPaired(); + void notify(NukiEventType eventType) override; + private: static void onLockActionReceived(const char* value); @@ -39,6 +41,7 @@ private: BatteryReport _lastBatteryReport; bool _paired = false; + bool _statusUpdated = false; unsigned long _nextLockStateUpdateTs = 0; unsigned long _nextBatteryReportTs = 0; LockAction _nextLockAction = (LockAction)0xff; diff --git a/lib/nuki_ble b/lib/nuki_ble index aa3fd59..d2a25ad 160000 --- a/lib/nuki_ble +++ b/lib/nuki_ble @@ -1 +1 @@ -Subproject commit aa3fd59f98710ce6073501896ff348d486637ac1 +Subproject commit d2a25adedd2862343ddc5e19ab2dedea2bd0da71