add code to query authorization data
This commit is contained in:
@@ -7,7 +7,7 @@ project(nuki_hub CXX)
|
||||
# ARDUHAL_LOG_LEVEL_NONE, define ARDUHAL_LOG_LEVEL_ERROR, define ARDUHAL_LOG_LEVEL_WARN, define ARDUHAL_LOG_LEVEL_INFO,
|
||||
# define ARDUHAL_LOG_LEVEL_DEBUG, define ARDUHAL_LOG_LEVEL_VERBOSE
|
||||
|
||||
set(LOG_LEVEL ARDUHAL_LOG_LEVEL_NONE)
|
||||
set(LOG_LEVEL ARDUHAL_LOG_LEVEL_DEBUG)
|
||||
|
||||
include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#define mqtt_topic_lock_state "/lock/state"
|
||||
#define mqtt_topic_lock_trigger "/lock/trigger"
|
||||
#define mqtt_topic_lock_auth_id "/lock/authorizationId"
|
||||
#define mqtt_topic_lock_auth_name "/lock/authorizationName"
|
||||
#define mqtt_topic_lock_completionStatus "/lock/completionStatus"
|
||||
#define mqtt_topic_lock_action_command_result "/lock/commandResult"
|
||||
#define mqtt_topic_door_sensor_state "/lock/doorSensorState"
|
||||
|
||||
16
Network.cpp
16
Network.cpp
@@ -286,6 +286,12 @@ void Network::publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState,
|
||||
_firstTunerStatePublish = false;
|
||||
}
|
||||
|
||||
void Network::publishAuthorizationInfo(const uint32_t authId, const char *authName)
|
||||
{
|
||||
publishUInt(mqtt_topic_lock_auth_id, authId);
|
||||
publishString(mqtt_topic_lock_auth_name, authName);
|
||||
}
|
||||
|
||||
void Network::publishCommandResult(const char *resultStr)
|
||||
{
|
||||
publishString(mqtt_topic_lock_action_command_result, resultStr);
|
||||
@@ -338,7 +344,6 @@ void Network::publishFloat(const char* topic, const float value, const uint8_t p
|
||||
|
||||
void Network::publishInt(const char *topic, const int value)
|
||||
{
|
||||
|
||||
char str[30];
|
||||
itoa(value, str, 10);
|
||||
char path[200] = {0};
|
||||
@@ -346,6 +351,15 @@ void Network::publishInt(const char *topic, const int value)
|
||||
_device->mqttClient()->publish(path, str);
|
||||
}
|
||||
|
||||
void Network::publishUInt(const char *topic, const unsigned int value)
|
||||
{
|
||||
char str[30];
|
||||
utoa(value, str, 10);
|
||||
char path[200] = {0};
|
||||
buildMqttPath(topic, path);
|
||||
_device->mqttClient()->publish(path, str);
|
||||
}
|
||||
|
||||
void Network::publishBool(const char *topic, const bool value)
|
||||
{
|
||||
char str[2] = {0};
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
bool isMqttConnected();
|
||||
|
||||
void publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState, const Nuki::KeyTurnerState& lastKeyTurnerState);
|
||||
void publishAuthorizationInfo(const uint32_t authId, const char* authName);
|
||||
void publishCommandResult(const char* resultStr);
|
||||
void publishBatteryReport(const Nuki::BatteryReport& batteryReport);
|
||||
void publishConfig(const Nuki::Config& config);
|
||||
@@ -47,6 +48,7 @@ private:
|
||||
|
||||
void publishFloat(const char* topic, const float value, const uint8_t precision = 2);
|
||||
void publishInt(const char* topic, const int value);
|
||||
void publishUInt(const char* topic, const unsigned int value);
|
||||
void publishBool(const char* topic, const bool value);
|
||||
void publishString(const char* topic, const char* value);
|
||||
|
||||
|
||||
@@ -101,6 +101,11 @@ void NukiWrapper::update()
|
||||
_nextConfigUpdateTs = ts + _intervalConfig * 1000;
|
||||
updateConfig();
|
||||
}
|
||||
if(_nextLogUpdateTs == 0 || ts > _nextLogUpdateTs)
|
||||
{
|
||||
_nextLogUpdateTs = ts + 10 * 1000;
|
||||
updateAuthInfo();
|
||||
}
|
||||
|
||||
if(_nextLockAction != (Nuki::LockAction)0xff)
|
||||
{
|
||||
@@ -141,6 +146,8 @@ void NukiWrapper::updateKeyTurnerState()
|
||||
Serial.print(F("Nuki lock state: "));
|
||||
Serial.println(lockStateStr);
|
||||
}
|
||||
|
||||
updateAuthInfo();
|
||||
}
|
||||
|
||||
void NukiWrapper::updateBatteryState()
|
||||
@@ -167,6 +174,54 @@ void NukiWrapper::updateConfig()
|
||||
_network->publishAdvancedConfig(_nukiAdvancedConfig);
|
||||
}
|
||||
|
||||
void NukiWrapper::updateAuthInfo()
|
||||
{
|
||||
return;
|
||||
|
||||
Nuki::CmdResult result = _nukiBle.retrieveLogEntries(0, 0, 0, true);
|
||||
if(result != Nuki::CmdResult::Success)
|
||||
{
|
||||
return;
|
||||
}
|
||||
vTaskDelay( 100 / portTICK_PERIOD_MS);
|
||||
|
||||
result = _nukiBle.retrieveLogEntries(_nukiBle.getLogEntryCount() - 2, 1, 0, false);
|
||||
if(result != Nuki::CmdResult::Success)
|
||||
{
|
||||
return;
|
||||
}
|
||||
vTaskDelay( 200 / portTICK_PERIOD_MS);
|
||||
|
||||
std::list<Nuki::LogEntry> log;
|
||||
_nukiBle.getLogEntries(&log);
|
||||
|
||||
if(log.size() > 0)
|
||||
{
|
||||
const Nuki::LogEntry& entry = log.front();
|
||||
// log_d("Log: %d-%d-%d %d:%d:%d %s", entry.timeStampYear, entry.timeStampMonth, entry.timeStampDay,
|
||||
// entry.timeStampHour, entry.timeStampMinute, entry.timeStampSecond, entry.name);
|
||||
if(entry.authId != _lastAuthId)
|
||||
{
|
||||
_network->publishAuthorizationInfo(entry.authId, (char *) entry.name);
|
||||
_lastAuthId = entry.authId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//struct __attribute__((packed)) LogEntry {
|
||||
// uint32_t index;
|
||||
// uint16_t timeStampYear;
|
||||
// uint8_t timeStampMonth;
|
||||
// uint8_t timeStampDay;
|
||||
// uint8_t timeStampHour;
|
||||
// uint8_t timeStampMinute;
|
||||
// uint8_t timeStampSecond;
|
||||
// uint32_t authId;
|
||||
// uint8_t name[32];
|
||||
// LoggingType loggingType;
|
||||
// uint8_t data[5];
|
||||
//};
|
||||
|
||||
Nuki::LockAction NukiWrapper::lockActionToEnum(const char *str)
|
||||
{
|
||||
if(strcmp(str, "unlock") == 0) return Nuki::LockAction::Unlock;
|
||||
|
||||
@@ -32,6 +32,7 @@ private:
|
||||
void updateKeyTurnerState();
|
||||
void updateBatteryState();
|
||||
void updateConfig();
|
||||
void updateAuthInfo();
|
||||
|
||||
void readConfig();
|
||||
void readAdvancedConfig();
|
||||
@@ -50,6 +51,8 @@ private:
|
||||
Nuki::KeyTurnerState _lastKeyTurnerState;
|
||||
Nuki::KeyTurnerState _keyTurnerState;
|
||||
|
||||
uint32_t _lastAuthId = 0xffff;
|
||||
|
||||
Nuki::BatteryReport _batteryReport;
|
||||
Nuki::BatteryReport _lastBatteryReport;
|
||||
|
||||
@@ -63,6 +66,7 @@ private:
|
||||
unsigned long _nextLockStateUpdateTs = 0;
|
||||
unsigned long _nextBatteryReportTs = 0;
|
||||
unsigned long _nextConfigUpdateTs = 0;
|
||||
unsigned long _nextLogUpdateTs = 0;
|
||||
unsigned long _nextPairTs = 0;
|
||||
Nuki::LockAction _nextLockAction = (Nuki::LockAction)0xff;
|
||||
};
|
||||
|
||||
Submodule lib/nuki_ble updated: ca70d497e1...e9fca7b48d
Reference in New Issue
Block a user