detect key turner state updates via scanning advertisements
This commit is contained in:
@@ -29,6 +29,7 @@ file(GLOB SRCFILES
|
|||||||
lib/nuki_ble/src/NukiBle.cpp
|
lib/nuki_ble/src/NukiBle.cpp
|
||||||
lib/nuki_ble/src/NukiConstants.h
|
lib/nuki_ble/src/NukiConstants.h
|
||||||
lib/nuki_ble/src/NukiUtills.h
|
lib/nuki_ble/src/NukiUtills.h
|
||||||
|
lib/nuki_ble/src/BleScanner.cpp
|
||||||
include_directories(Lib/PubSubClient)
|
include_directories(Lib/PubSubClient)
|
||||||
lib/pubsubclient/src/PubSubClient.cpp
|
lib/pubsubclient/src/PubSubClient.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
20
Nuki.cpp
20
Nuki.cpp
@@ -37,6 +37,8 @@ void Nuki::initialize()
|
|||||||
_preferences->putInt(preference_query_interval_battery, _intervalBattery);
|
_preferences->putInt(preference_query_interval_battery, _intervalBattery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_nukiBle.setEventHandler(this);
|
||||||
|
|
||||||
Serial.print(F("Lock state interval: "));
|
Serial.print(F("Lock state interval: "));
|
||||||
Serial.print(_intervalLockstate);
|
Serial.print(_intervalLockstate);
|
||||||
Serial.print(F("| Battery interval: "));
|
Serial.print(F("| Battery interval: "));
|
||||||
@@ -63,8 +65,9 @@ void Nuki::update()
|
|||||||
|
|
||||||
unsigned long ts = millis();
|
unsigned long ts = millis();
|
||||||
|
|
||||||
if(_nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs)
|
if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs)
|
||||||
{
|
{
|
||||||
|
_statusUpdated = false;
|
||||||
_nextLockStateUpdateTs = ts + _intervalLockstate * 1000;
|
_nextLockStateUpdateTs = ts + _intervalLockstate * 1000;
|
||||||
updateKeyTurnerState();
|
updateKeyTurnerState();
|
||||||
}
|
}
|
||||||
@@ -78,6 +81,7 @@ void Nuki::update()
|
|||||||
_nukiBle.lockAction(_nextLockAction, 0, 0);
|
_nukiBle.lockAction(_nextLockAction, 0, 0);
|
||||||
_nextLockAction = (LockAction)0xff;
|
_nextLockAction = (LockAction)0xff;
|
||||||
}
|
}
|
||||||
|
_nukiBle.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Nuki::updateKeyTurnerState()
|
void Nuki::updateKeyTurnerState()
|
||||||
@@ -94,9 +98,9 @@ void Nuki::updateKeyTurnerState()
|
|||||||
if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState)
|
if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState)
|
||||||
{
|
{
|
||||||
_network->publishKeyTurnerState(lockStateStr, triggerStr, completionStatusStr);
|
_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));
|
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(KeyTurnerState));
|
||||||
}
|
}
|
||||||
@@ -244,7 +248,6 @@ LockAction Nuki::lockActionToEnum(const char *str)
|
|||||||
return (LockAction)0xff;
|
return (LockAction)0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Nuki::onLockActionReceived(const char *value)
|
void Nuki::onLockActionReceived(const char *value)
|
||||||
{
|
{
|
||||||
nukiInst->_nextLockAction = nukiInst->lockActionToEnum(value);
|
nukiInst->_nextLockAction = nukiInst->lockActionToEnum(value);
|
||||||
@@ -256,3 +259,12 @@ const bool Nuki::isPaired()
|
|||||||
{
|
{
|
||||||
return _paired;
|
return _paired;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Nuki::notify(NukiEventType eventType)
|
||||||
|
{
|
||||||
|
if(eventType == NukiEventType::KeyTurnerStatusUpdated)
|
||||||
|
{
|
||||||
|
// Serial.println("SUP2");
|
||||||
|
_statusUpdated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
5
Nuki.h
5
Nuki.h
@@ -4,7 +4,7 @@
|
|||||||
#include "NukiConstants.h"
|
#include "NukiConstants.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
|
|
||||||
class Nuki
|
class Nuki : public NukiSmartlockEventHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Nuki(const std::string& name, uint32_t id, Network* network, Preferences* preferences);
|
Nuki(const std::string& name, uint32_t id, Network* network, Preferences* preferences);
|
||||||
@@ -14,6 +14,8 @@ public:
|
|||||||
|
|
||||||
const bool isPaired();
|
const bool isPaired();
|
||||||
|
|
||||||
|
void notify(NukiEventType eventType) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onLockActionReceived(const char* value);
|
static void onLockActionReceived(const char* value);
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ private:
|
|||||||
BatteryReport _lastBatteryReport;
|
BatteryReport _lastBatteryReport;
|
||||||
|
|
||||||
bool _paired = false;
|
bool _paired = false;
|
||||||
|
bool _statusUpdated = false;
|
||||||
unsigned long _nextLockStateUpdateTs = 0;
|
unsigned long _nextLockStateUpdateTs = 0;
|
||||||
unsigned long _nextBatteryReportTs = 0;
|
unsigned long _nextBatteryReportTs = 0;
|
||||||
LockAction _nextLockAction = (LockAction)0xff;
|
LockAction _nextLockAction = (LockAction)0xff;
|
||||||
|
|||||||
Submodule lib/nuki_ble updated: aa3fd59f98...d2a25adedd
Reference in New Issue
Block a user