Merge pull request #73 from technyon/rvt-libs

merge to master
This commit is contained in:
Jan-Ole Schümann
2023-01-11 23:11:26 +01:00
committed by GitHub
15 changed files with 94 additions and 40 deletions

View File

@@ -20,6 +20,7 @@
#define mqtt_topic_lock_door_sensor_state "/lock/doorSensorState" #define mqtt_topic_lock_door_sensor_state "/lock/doorSensorState"
#define mqtt_topic_lock_action "/lock/action" #define mqtt_topic_lock_action "/lock/action"
#define mqtt_topic_lock_rssi "/lock/rssi" #define mqtt_topic_lock_rssi "/lock/rssi"
#define mqtt_topic_lock_address "/lock/address"
#define mqtt_topic_config_button_enabled "/configuration/buttonEnabled" #define mqtt_topic_config_button_enabled "/configuration/buttonEnabled"
#define mqtt_topic_config_led_enabled "/configuration/ledEnabled" #define mqtt_topic_config_led_enabled "/configuration/ledEnabled"

View File

@@ -388,6 +388,11 @@ void NetworkLock::publishRssi(const int& rssi)
publishInt(mqtt_topic_lock_rssi, rssi); publishInt(mqtt_topic_lock_rssi, rssi);
} }
void NetworkLock::publishBleAddress(const std::string &address)
{
publishString(mqtt_topic_lock_address, address.c_str());
}
void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount) void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount)
{ {
uint index = 0; uint index = 0;

View File

@@ -28,6 +28,7 @@ public:
void publishConfig(const NukiLock::Config& config); void publishConfig(const NukiLock::Config& config);
void publishAdvancedConfig(const NukiLock::AdvancedConfig& config); void publishAdvancedConfig(const NukiLock::AdvancedConfig& config);
void publishRssi(const int& rssi); void publishRssi(const int& rssi);
void publishBleAddress(const std::string& address);
void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState); void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState);
void removeHASSConfig(char* uidString); void removeHASSConfig(char* uidString);
void publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount); void publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount);

View File

@@ -97,15 +97,23 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
{ {
char str[50]; char str[50];
if((_firstTunerStatePublish || keyTurnerState.lockState != lastKeyTurnerState.lockState) && keyTurnerState.lockState != NukiOpener::LockState::Undefined) if((_firstTunerStatePublish || keyTurnerState.lockState != lastKeyTurnerState.lockState || keyTurnerState.nukiState != lastKeyTurnerState.nukiState) && keyTurnerState.lockState != NukiOpener::LockState::Undefined)
{ {
memset(&str, 0, sizeof(str)); memset(&str, 0, sizeof(str));
if(keyTurnerState.nukiState == NukiOpener::State::ContinuousMode)
{
publishString(mqtt_topic_lock_state, "ContinuousMode");
}
else
{
lockstateToString(keyTurnerState.lockState, str); lockstateToString(keyTurnerState.lockState, str);
publishString(mqtt_topic_lock_state, str); publishString(mqtt_topic_lock_state, str);
}
if(_haEnabled) if(_haEnabled)
{ {
publishBinaryState(keyTurnerState.lockState); publishBinaryState(keyTurnerState);
} }
} }
@@ -145,9 +153,15 @@ void NetworkOpener::publishRing()
_resetLockStateTs = millis() + 2000; _resetLockStateTs = millis() + 2000;
} }
void NetworkOpener::publishBinaryState(NukiOpener::LockState lockState) void NetworkOpener::publishBinaryState(NukiOpener::OpenerState lockState)
{ {
switch(lockState) if(lockState.nukiState == NukiOpener::State::ContinuousMode)
{
publishString(mqtt_topic_lock_binary_state, "unlocked");
}
else
{
switch (lockState.lockState)
{ {
case NukiOpener::LockState::Locked: case NukiOpener::LockState::Locked:
publishString(mqtt_topic_lock_binary_state, "locked"); publishString(mqtt_topic_lock_binary_state, "locked");
@@ -160,6 +174,7 @@ void NetworkOpener::publishBinaryState(NukiOpener::LockState lockState)
default: default:
break; break;
} }
}
} }
void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntry>& logEntries) void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntry>& logEntries)
@@ -367,6 +382,11 @@ void NetworkOpener::publishRssi(const int &rssi)
publishInt(mqtt_topic_lock_rssi, rssi); publishInt(mqtt_topic_lock_rssi, rssi);
} }
void NetworkOpener::publishBleAddress(const std::string &address)
{
publishString(mqtt_topic_lock_address, address.c_str());
}
void NetworkOpener::publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState) void NetworkOpener::publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState)
{ {
_network->publishHASSConfig(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState); _network->publishHASSConfig(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState);
@@ -449,4 +469,3 @@ bool NetworkOpener::comparePrefixedPath(const char *fullPath, const char *subPat
buildMqttPath(subPath, prefixedPath); buildMqttPath(subPath, prefixedPath);
return strcmp(fullPath, prefixedPath) == 0; return strcmp(fullPath, prefixedPath) == 0;
} }

View File

@@ -21,7 +21,7 @@ public:
void publishKeyTurnerState(const NukiOpener::OpenerState& keyTurnerState, const NukiOpener::OpenerState& lastKeyTurnerState); void publishKeyTurnerState(const NukiOpener::OpenerState& keyTurnerState, const NukiOpener::OpenerState& lastKeyTurnerState);
void publishRing(); void publishRing();
void publishBinaryState(NukiOpener::LockState lockState); void publishBinaryState(NukiOpener::OpenerState lockState);
void publishAuthorizationInfo(const std::list<NukiOpener::LogEntry>& logEntries); void publishAuthorizationInfo(const std::list<NukiOpener::LogEntry>& logEntries);
void clearAuthorizationInfo(); void clearAuthorizationInfo();
void publishCommandResult(const char* resultStr); void publishCommandResult(const char* resultStr);
@@ -29,6 +29,7 @@ public:
void publishConfig(const NukiOpener::Config& config); void publishConfig(const NukiOpener::Config& config);
void publishAdvancedConfig(const NukiOpener::AdvancedConfig& config); void publishAdvancedConfig(const NukiOpener::AdvancedConfig& config);
void publishRssi(const int& rssi); void publishRssi(const int& rssi);
void publishBleAddress(const std::string& address);
void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState); void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState);
void removeHASSConfig(char* uidString); void removeHASSConfig(char* uidString);

View File

@@ -75,14 +75,17 @@ void NukiOpenerWrapper::update()
if (!_paired) if (!_paired)
{ {
Log->println(F("Nuki opener start pairing")); Log->println(F("Nuki opener start pairing"));
_network->publishBleAddress("");
Nuki::AuthorizationIdType idType = _preferences->getBool(preference_register_as_app) ? Nuki::AuthorizationIdType idType = _preferences->getBool(preference_register_as_app) ?
Nuki::AuthorizationIdType::App : Nuki::AuthorizationIdType::App :
Nuki::AuthorizationIdType::Bridge; Nuki::AuthorizationIdType::Bridge;
if (_nukiOpener.pairNuki(idType) == NukiOpener::PairingResult::Success) { if (_nukiOpener.pairNuki(idType) == NukiOpener::PairingResult::Success)
{
Log->println(F("Nuki opener paired")); Log->println(F("Nuki opener paired"));
_paired = true; _paired = true;
_network->publishBleAddress(_nukiOpener.getBleAddress().toString());
} }
else else
{ {
@@ -91,7 +94,12 @@ void NukiOpenerWrapper::update()
} }
} }
if(_restartBeaconTimeout > 0 && (millis() - _nukiOpener.getLastReceivedBeaconTs() > _restartBeaconTimeout * 1000)) unsigned long ts = millis();
unsigned long lastReceivedBeaconTs = _nukiOpener.getLastReceivedBeaconTs();
if(_restartBeaconTimeout > 0 &&
ts > 60000 &&
lastReceivedBeaconTs > 0 &&
(ts - lastReceivedBeaconTs > _restartBeaconTimeout * 1000))
{ {
Log->print("No BLE beacon received from the opener for "); Log->print("No BLE beacon received from the opener for ");
Log->print((millis() - _nukiOpener.getLastReceivedBeaconTs()) / 1000); Log->print((millis() - _nukiOpener.getLastReceivedBeaconTs()) / 1000);
@@ -102,8 +110,6 @@ void NukiOpenerWrapper::update()
_nukiOpener.updateConnectionState(); _nukiOpener.updateConnectionState();
unsigned long ts = millis();
if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs) if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs)
{ {
_nextLockStateUpdateTs = ts + _intervalLockstate * 1000; _nextLockStateUpdateTs = ts + _intervalLockstate * 1000;
@@ -179,7 +185,10 @@ void NukiOpenerWrapper::updateKeyTurnerState()
{ {
_nukiOpener.requestOpenerState(&_keyTurnerState); _nukiOpener.requestOpenerState(&_keyTurnerState);
if(_statusUpdated && _keyTurnerState.lockState == NukiOpener::LockState::Locked && _lastKeyTurnerState.lockState == NukiOpener::LockState::Locked) if(_statusUpdated &&
_keyTurnerState.lockState == NukiOpener::LockState::Locked &&
_lastKeyTurnerState.lockState == NukiOpener::LockState::Locked &&
_lastKeyTurnerState.nukiState == _keyTurnerState.nukiState)
{ {
Log->println(F("Nuki opener: Ring detected")); Log->println(F("Nuki opener: Ring detected"));
_network->publishRing(); _network->publishRing();
@@ -188,7 +197,11 @@ void NukiOpenerWrapper::updateKeyTurnerState()
{ {
_network->publishKeyTurnerState(_keyTurnerState, _lastKeyTurnerState); _network->publishKeyTurnerState(_keyTurnerState, _lastKeyTurnerState);
if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState) if(_keyTurnerState.nukiState == NukiOpener::State::ContinuousMode)
{
Log->println(F("Nuki opener state: Continuous Mode"));
}
else if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState)
{ {
char lockStateStr[20]; char lockStateStr[20];
lockstateToString(_keyTurnerState.lockState, lockStateStr); lockstateToString(_keyTurnerState.lockState, lockStateStr);
@@ -305,6 +318,11 @@ const bool NukiOpenerWrapper::isPaired()
return _paired; return _paired;
} }
const BLEAddress NukiOpenerWrapper::getBleAddress() const
{
return _nukiOpener.getBleAddress();
}
BleScanner::Scanner *NukiOpenerWrapper::bleScanner() BleScanner::Scanner *NukiOpenerWrapper::bleScanner()
{ {
return _bleScanner; return _bleScanner;

View File

@@ -23,6 +23,7 @@ public:
const NukiOpener::OpenerState& keyTurnerState(); const NukiOpener::OpenerState& keyTurnerState();
const bool isPaired(); const bool isPaired();
const BLEAddress getBleAddress() const;
BleScanner::Scanner* bleScanner(); BleScanner::Scanner* bleScanner();

View File

@@ -87,21 +87,20 @@ void NukiWrapper::initialize()
void NukiWrapper::update() void NukiWrapper::update()
{ {
Nuki::AuthorizationIdType idType = _preferences->getBool(preference_register_as_app) ?
Nuki::AuthorizationIdType::App :
Nuki::AuthorizationIdType::Bridge;
if (!_paired) if (!_paired)
{ {
Log->println(F("Nuki start pairing")); Log->println(F("Nuki start pairing"));
_network->publishBleAddress("");
Nuki::AuthorizationIdType idType = _preferences->getBool(preference_register_as_app) ? Nuki::AuthorizationIdType idType = _preferences->getBool(preference_register_as_app) ?
Nuki::AuthorizationIdType::App : Nuki::AuthorizationIdType::App :
Nuki::AuthorizationIdType::Bridge; Nuki::AuthorizationIdType::Bridge;
if (_nukiLock.pairNuki(idType) == Nuki::PairingResult::Success) { if (_nukiLock.pairNuki(idType) == Nuki::PairingResult::Success)
{
Log->println(F("Nuki paired")); Log->println(F("Nuki paired"));
_paired = true; _paired = true;
_network->publishBleAddress(_nukiLock.getBleAddress().toString());
} }
else else
{ {
@@ -110,7 +109,12 @@ void NukiWrapper::update()
} }
} }
if(_restartBeaconTimeout > 0 && (millis() - _nukiLock.getLastReceivedBeaconTs() > _restartBeaconTimeout * 1000)) unsigned long ts = millis();
unsigned long lastReceivedBeaconTs = _nukiLock.getLastReceivedBeaconTs();
if(_restartBeaconTimeout > 0 &&
ts > 60000 &&
lastReceivedBeaconTs > 0 &&
(ts - lastReceivedBeaconTs > _restartBeaconTimeout * 1000))
{ {
Log->print("No BLE beacon received from the lock for "); Log->print("No BLE beacon received from the lock for ");
Log->print((millis() - _nukiLock.getLastReceivedBeaconTs()) / 1000); Log->print((millis() - _nukiLock.getLastReceivedBeaconTs()) / 1000);
@@ -121,8 +125,6 @@ void NukiWrapper::update()
_nukiLock.updateConnectionState(); _nukiLock.updateConnectionState();
unsigned long ts = millis();
if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs) if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs)
{ {
_statusUpdated = false; _statusUpdated = false;
@@ -576,3 +578,8 @@ void NukiWrapper::disableHASS()
Log->println(F("Unable to disable HASS. Invalid config received.")); Log->println(F("Unable to disable HASS. Invalid config received."));
} }
} }
const BLEAddress NukiWrapper::getBleAddress() const
{
return _nukiLock.getBleAddress();
}

View File

@@ -27,6 +27,7 @@ public:
const NukiLock::KeyTurnerState& keyTurnerState(); const NukiLock::KeyTurnerState& keyTurnerState();
const bool isPaired(); const bool isPaired();
const bool hasKeypad(); const bool hasKeypad();
const BLEAddress getBleAddress() const;
void notify(Nuki::EventType eventType) override; void notify(Nuki::EventType eventType) override;

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define nuki_hub_version "6.8" #define nuki_hub_version "6.9"

View File

@@ -450,14 +450,14 @@ void WebCfgServer::buildHtml(String& response)
{ {
char lockstateArr[20]; char lockstateArr[20];
NukiLock::lockstateToString(_nuki->keyTurnerState().lockState, lockstateArr); NukiLock::lockstateToString(_nuki->keyTurnerState().lockState, lockstateArr);
printParameter(response, "NUKI Lock paired", _nuki->isPaired() ? "Yes" : "No"); printParameter(response, "NUKI Lock paired", _nuki->isPaired() ? ("Yes (BLE Address " + _nuki->getBleAddress().toString() + ")").c_str() : "No");
printParameter(response, "NUKI Lock state", lockstateArr); printParameter(response, "NUKI Lock state", lockstateArr);
} }
if(_nukiOpener != nullptr) if(_nukiOpener != nullptr)
{ {
char lockstateArr[20]; char lockstateArr[20];
NukiOpener::lockstateToString(_nukiOpener->keyTurnerState().lockState, lockstateArr); NukiOpener::lockstateToString(_nukiOpener->keyTurnerState().lockState, lockstateArr);
printParameter(response, "NUKI Opener paired", _nukiOpener->isPaired() ? "Yes" : "No"); printParameter(response, "NUKI Opener paired", _nuki->isPaired() ? ("Yes (BLE Address " + _nukiOpener->getBleAddress().toString() + ")").c_str() : "No");
printParameter(response, "NUKI Opener state", lockstateArr); printParameter(response, "NUKI Opener state", lockstateArr);
} }
printParameter(response, "Firmware", version.c_str()); printParameter(response, "Firmware", version.c_str());

View File

@@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file.
### Fixed ### Fixed
- Compile warning removed for esp32c3 - Compile warning removed for esp32c3
- NimBLEDevice::getPower incorrect value when power level is -3db. - NimBLEDevice::getPower incorrect value when power level is -3db.
- Failure pairing when already in progress. - Failed pairing when already in progress.
### Changed ### Changed
- Revert previous change that forced writing with response when subscribing in favor of allowing the application to decide. - Revert previous change that forced writing with response when subscribing in favor of allowing the application to decide.

View File

@@ -38,7 +38,7 @@ PROJECT_NAME = NimBLE-Arduino
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # control system is used.
PROJECT_NUMBER = 1.4.1 PROJECT_NUMBER = 1.4.0
# Using the PROJECT_BRIEF tag one can provide an optional one line description # Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a # for a project that appears at the top of each page and should give viewer a
@@ -58,7 +58,7 @@ PROJECT_LOGO =
# entered, it will be relative to the location where doxygen was started. If # entered, it will be relative to the location where doxygen was started. If
# left blank the current directory will be used. # left blank the current directory will be used.
OUTPUT_DIRECTORY = doxydocs OUTPUT_DIRECTORY = docs
# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
# directories (in 2 levels) under the output directory of each output format and # directories (in 2 levels) under the output directory of each output format and
@@ -836,7 +836,7 @@ WARN_NO_PARAMDOC = NO
# Possible values are: NO, YES and FAIL_ON_WARNINGS. # Possible values are: NO, YES and FAIL_ON_WARNINGS.
# The default value is: NO. # The default value is: NO.
WARN_AS_ERROR = YES WARN_AS_ERROR = FAIL_ON_WARNINGS
# The WARN_FORMAT tag determines the format of the warning messages that doxygen # The WARN_FORMAT tag determines the format of the warning messages that doxygen
# can produce. The string should contain the $file, $line, and $text tags, which # can produce. The string should contain the $file, $line, and $text tags, which

Binary file not shown.