Arduino Core 3 (#407)
* Add and remove libs and components for Arduino Core 3 * Arduino Core 3 * Add back Solo1 * Change ESP32-S3 to 4MB build * Update README.md * Fix retain and number of retries * Fix rolling log * Fix defaults * Fix BleScanner on Solo1 * Export settings * Import settings * Fix HA Battery voltage * Change submodule * Update espMqttClient and AsyncTCP * Webserial and MQTT/Network reconnecting * Update nuki_ble --------- Co-authored-by: iranl <iranl@github.com>
This commit is contained in:
@@ -8,10 +8,10 @@
|
||||
#include "Config.h"
|
||||
|
||||
NukiWrapper* nukiInst;
|
||||
NetworkLock* networkInst;
|
||||
NukiNetworkLock* networkInst;
|
||||
Preferences* nukiLockPreferences = nullptr;
|
||||
|
||||
NukiWrapper::NukiWrapper(const std::string& deviceName, NukiDeviceId* deviceId, BleScanner::Scanner* scanner, NetworkLock* network, Gpio* gpio, Preferences* preferences)
|
||||
NukiWrapper::NukiWrapper(const std::string& deviceName, NukiDeviceId* deviceId, BleScanner::Scanner* scanner, NukiNetworkLock* network, Gpio* gpio, Preferences* preferences)
|
||||
: _deviceName(deviceName),
|
||||
_deviceId(deviceId),
|
||||
_bleScanner(scanner),
|
||||
@@ -72,65 +72,106 @@ void NukiWrapper::initialize(const bool& firstStart)
|
||||
|
||||
if(firstStart)
|
||||
{
|
||||
Log->println("First start, setting preference defaults");
|
||||
_preferences->putBool(preference_network_wifi_fallback_disabled, false);
|
||||
_preferences->putBool(preference_find_best_rssi, false);
|
||||
_preferences->putBool(preference_check_updates, true);
|
||||
_preferences->putBool(preference_opener_continuous_mode, false);
|
||||
_preferences->putBool(preference_network_wifi_fallback_disabled, false);
|
||||
_preferences->putBool(preference_official_hybrid, false);
|
||||
_preferences->putBool(preference_official_hybrid_actions, false);
|
||||
_preferences->putBool(preference_official_hybrid_retry, false);
|
||||
_preferences->putBool(preference_disable_non_json, false);
|
||||
_preferences->putBool(preference_update_from_mqtt, false);
|
||||
_preferences->putBool(preference_ip_dhcp_enabled, true);
|
||||
_preferences->putBool(preference_enable_bootloop_reset, false);
|
||||
_preferences->putBool(preference_show_secrets, false);
|
||||
|
||||
_preferences->putBool(preference_conf_info_enabled, true);
|
||||
_preferences->putBool(preference_keypad_info_enabled, false);
|
||||
_preferences->putBool(preference_keypad_topic_per_entry, false);
|
||||
_preferences->putBool(preference_keypad_publish_code, false);
|
||||
_preferences->putBool(preference_keypad_control_enabled, false);
|
||||
_preferences->putBool(preference_timecontrol_info_enabled, false);
|
||||
_preferences->putBool(preference_timecontrol_topic_per_entry, false);
|
||||
_preferences->putBool(preference_timecontrol_control_enabled, false);
|
||||
_preferences->putBool(preference_publish_authdata, false);
|
||||
_preferences->putBool(preference_register_as_app, false);
|
||||
_preferences->putBool(preference_register_opener_as_app, false);
|
||||
|
||||
_preferences->putInt(preference_mqtt_broker_port, 1883);
|
||||
_preferences->putInt(preference_buffer_size, CHAR_BUFFER_SIZE);
|
||||
_preferences->putInt(preference_task_size_network, NETWORK_TASK_SIZE);
|
||||
_preferences->putInt(preference_task_size_nuki, NUKI_TASK_SIZE);
|
||||
_preferences->putInt(preference_authlog_max_entries, MAX_AUTHLOG);
|
||||
_preferences->putInt(preference_keypad_max_entries, MAX_KEYPAD);
|
||||
_preferences->putInt(preference_timecontrol_max_entries, MAX_TIMECONTROL);
|
||||
_preferences->putInt(preference_query_interval_hybrid_lockstate, 600);
|
||||
_preferences->putInt(preference_rssi_publish_interval, 60);
|
||||
_preferences->putInt(preference_network_timeout, 60);
|
||||
_preferences->putInt(preference_command_nr_of_retries, 3);
|
||||
_preferences->putInt(preference_command_retry_delay, 1000);
|
||||
_preferences->putInt(preference_restart_ble_beacon_lost, 60);
|
||||
uint32_t aclPrefs[17] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
_preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs));
|
||||
uint32_t basicLockConfigAclPrefs[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
_preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs));
|
||||
uint32_t basicOpenerConfigAclPrefs[14] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
_preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs));
|
||||
uint32_t advancedLockConfigAclPrefs[22] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
_preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs));
|
||||
uint32_t advancedOpenerConfigAclPrefs[20] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
_preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs));
|
||||
_preferences->putInt(preference_query_interval_lockstate, 1800);
|
||||
_preferences->putInt(preference_query_interval_configuration, 3600);
|
||||
_preferences->putInt(preference_query_interval_battery, 1800);
|
||||
_preferences->putInt(preference_query_interval_keypad, 1800);
|
||||
_preferences->putInt(preference_presence_detection_timeout, -1);
|
||||
}
|
||||
|
||||
if(_nrOfRetries < 0 || _nrOfRetries == 200)
|
||||
{
|
||||
Log->println("Invalid nrOfRetries, revert to default (3)");
|
||||
_nrOfRetries = 3;
|
||||
_preferences->putInt(preference_command_nr_of_retries, _nrOfRetries);
|
||||
}
|
||||
|
||||
if(_retryDelay <= 100)
|
||||
{
|
||||
Log->println("Invalid retryDelay, revert to default (100)");
|
||||
_retryDelay = 100;
|
||||
_preferences->putInt(preference_command_retry_delay, _retryDelay);
|
||||
}
|
||||
|
||||
if(_intervalLockstate == 0)
|
||||
{
|
||||
Log->println("Invalid intervalLockstate, revert to default (1800)");
|
||||
_intervalLockstate = 60 * 30;
|
||||
_preferences->putInt(preference_query_interval_lockstate, _intervalLockstate);
|
||||
}
|
||||
if(_intervalHybridLockstate == 0)
|
||||
{
|
||||
Log->println("Invalid intervalHybridLockstate, revert to default (600)");
|
||||
_intervalHybridLockstate = 60 * 10;
|
||||
_preferences->putInt(preference_query_interval_hybrid_lockstate, _intervalHybridLockstate);
|
||||
}
|
||||
if(_intervalConfig == 0)
|
||||
{
|
||||
Log->println("Invalid intervalConfig, revert to default (3600)");
|
||||
_intervalConfig = 60 * 60;
|
||||
_preferences->putInt(preference_query_interval_configuration, _intervalConfig);
|
||||
}
|
||||
if(_intervalBattery == 0)
|
||||
{
|
||||
Log->println("Invalid intervalBattery, revert to default (1800)");
|
||||
_intervalBattery = 60 * 30;
|
||||
_preferences->putInt(preference_query_interval_battery, _intervalBattery);
|
||||
}
|
||||
if(_intervalKeypad == 0)
|
||||
{
|
||||
Log->println("Invalid intervalKeypad, revert to default (1800)");
|
||||
_intervalKeypad = 60 * 30;
|
||||
_preferences->putInt(preference_query_interval_keypad, _intervalKeypad);
|
||||
}
|
||||
if(_restartBeaconTimeout < 10)
|
||||
{
|
||||
Log->println("Invalid restartBeaconTimeout, revert to default (-1)");
|
||||
_restartBeaconTimeout = -1;
|
||||
_preferences->putInt(preference_restart_ble_beacon_lost, _restartBeaconTimeout);
|
||||
}
|
||||
|
||||
|
||||
_nukiLock.setEventHandler(this);
|
||||
_nukiLock.setDisonnectTimeout(5000);
|
||||
|
||||
Log->print(F("Lock state interval: "));
|
||||
Log->print(_intervalLockstate);
|
||||
@@ -150,6 +191,7 @@ void NukiWrapper::update()
|
||||
if(!_paired)
|
||||
{
|
||||
Log->println(F("Nuki lock start pairing"));
|
||||
_preferences->getBool(preference_register_as_app) ? Log->println(F("Pairing as app")) : Log->println(F("Pairing as bridge"));
|
||||
_network->publishBleAddress("");
|
||||
|
||||
Nuki::AuthorizationIdType idType = _preferences->getBool(preference_register_as_app) ?
|
||||
@@ -190,6 +232,7 @@ void NukiWrapper::update()
|
||||
|
||||
if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs || (queryCommands & QUERY_COMMAND_LOCKSTATE) > 0)
|
||||
{
|
||||
Log->println("Updating Lock state based on timer or query");
|
||||
_statusUpdated = false;
|
||||
_nextLockStateUpdateTs = ts + _intervalLockstate * 1000;
|
||||
updateKeyTurnerState();
|
||||
@@ -202,11 +245,13 @@ void NukiWrapper::update()
|
||||
}
|
||||
if(_nextBatteryReportTs == 0 || ts > _nextBatteryReportTs || (queryCommands & QUERY_COMMAND_BATTERY) > 0)
|
||||
{
|
||||
Log->println("Updating Lock battery state based on timer or query");
|
||||
_nextBatteryReportTs = ts + _intervalBattery * 1000;
|
||||
updateBatteryState();
|
||||
}
|
||||
if(_nextConfigUpdateTs == 0 || ts > _nextConfigUpdateTs || (queryCommands & QUERY_COMMAND_CONFIG) > 0)
|
||||
{
|
||||
Log->println("Updating Lock config based on timer or query");
|
||||
_nextConfigUpdateTs = ts + _intervalConfig * 1000;
|
||||
updateConfig();
|
||||
if(_hassEnabled && !_hassSetupCompleted)
|
||||
@@ -247,23 +292,14 @@ void NukiWrapper::update()
|
||||
|
||||
if(_hasKeypad && _keypadEnabled && (_nextKeypadUpdateTs == 0 || ts > _nextKeypadUpdateTs || (queryCommands & QUERY_COMMAND_KEYPAD) > 0))
|
||||
{
|
||||
Log->println("Updating Lock keypad based on timer or query");
|
||||
_nextKeypadUpdateTs = ts + _intervalKeypad * 1000;
|
||||
updateKeypad(false);
|
||||
}
|
||||
|
||||
if(_nextLockAction != (NukiLock::LockAction)0xff && ts > _nextRetryTs)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
Nuki::CmdResult cmdResult = _nukiLock.lockAction(_nextLockAction, 0, 0);
|
||||
_taskRunning = false;
|
||||
|
||||
char resultStr[15] = {0};
|
||||
NukiLock::cmdResultToString(cmdResult, resultStr);
|
||||
@@ -315,6 +351,7 @@ void NukiWrapper::update()
|
||||
|
||||
if(_clearAuthData)
|
||||
{
|
||||
Log->println("Clearing Lock auth data");
|
||||
_network->clearAuthorizationInfo();
|
||||
_clearAuthData = false;
|
||||
}
|
||||
@@ -376,28 +413,23 @@ void NukiWrapper::unpair()
|
||||
|
||||
void NukiWrapper::updateKeyTurnerState()
|
||||
{
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
Log->println("Querying lock state");
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
Log->print(F("Querying lock state: "));
|
||||
Log->print(F("Result (attempt "));
|
||||
Log->print(_retryCount + 1);
|
||||
Log->print("): ");
|
||||
result =_nukiLock.requestKeyTurnerState(&_keyTurnerState);
|
||||
_taskRunning = false;
|
||||
if(!_nukiConfigValid) {
|
||||
delay(250);
|
||||
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
char resultStr[15];
|
||||
@@ -407,10 +439,14 @@ void NukiWrapper::updateKeyTurnerState()
|
||||
|
||||
if(result != Nuki::CmdResult::Success)
|
||||
{
|
||||
Log->println("Query lock state failed");
|
||||
_retryLockstateCount++;
|
||||
postponeBleWatchdog();
|
||||
if(_retryLockstateCount < _nrOfRetries)
|
||||
if(_retryLockstateCount < _nrOfRetries + 1)
|
||||
{
|
||||
Log->print(F("Query lock state retrying in "));
|
||||
Log->print(_retryDelay);
|
||||
Log->println("ms");
|
||||
_nextLockStateUpdateTs = millis() + _retryDelay;
|
||||
}
|
||||
return;
|
||||
@@ -438,28 +474,22 @@ void NukiWrapper::updateKeyTurnerState()
|
||||
|
||||
void NukiWrapper::updateBatteryState()
|
||||
{
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
Log->println("Querying lock battery state");
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
Log->print(F("Querying lock battery state: "));
|
||||
Log->print(F("Result (attempt "));
|
||||
Log->print(_retryCount + 1);
|
||||
Log->print("): ");
|
||||
result = _nukiLock.requestBatteryReport(&_batteryReport);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
printCommandResult(result);
|
||||
@@ -482,6 +512,13 @@ void NukiWrapper::updateConfig()
|
||||
{
|
||||
if(_preferences->getUInt(preference_nuki_id_lock, 0) == 0 || _retryConfigCount == 10)
|
||||
{
|
||||
char uidString[20];
|
||||
itoa(_nukiConfig.nukiId, uidString, 16);
|
||||
Log->print(F("Saving Nuki ID to preferences ("));
|
||||
Log->print(_nukiConfig.nukiId);
|
||||
Log->print(" / ");
|
||||
Log->print(uidString);
|
||||
Log->println(")");
|
||||
_preferences->putUInt(preference_nuki_id_lock, _nukiConfig.nukiId);
|
||||
}
|
||||
|
||||
@@ -498,37 +535,30 @@ void NukiWrapper::updateConfig()
|
||||
const int pinStatus = _preferences->getInt(preference_lock_pin_status, 4);
|
||||
|
||||
if(isPinSet()) {
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
Log->println(F("Nuki Lock PIN is set"));
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.verifySecurityPin();
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if(result != Nuki::CmdResult::Success)
|
||||
{
|
||||
if(pinStatus != 2) {
|
||||
Log->println(F("Nuki Lock PIN is invalid"));
|
||||
if(pinStatus != 2) {
|
||||
_preferences->putInt(preference_lock_pin_status, 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println(F("Nuki Lock PIN is valid"));
|
||||
if(pinStatus != 1) {
|
||||
_preferences->putInt(preference_lock_pin_status, 1);
|
||||
}
|
||||
@@ -536,6 +566,7 @@ void NukiWrapper::updateConfig()
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println(F("Nuki Lock PIN is not set"));
|
||||
if(pinStatus != 0) {
|
||||
_preferences->putInt(preference_lock_pin_status, 0);
|
||||
}
|
||||
@@ -543,12 +574,14 @@ void NukiWrapper::updateConfig()
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println(F("Invalid/Unexpected config recieved, retrying"));
|
||||
expectedConfig = false;
|
||||
++_retryConfigCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println(F("Invalid/Unexpected config recieved, retrying"));
|
||||
expectedConfig = false;
|
||||
++_retryConfigCount;
|
||||
}
|
||||
@@ -559,6 +592,7 @@ void NukiWrapper::updateConfig()
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println(F("Invalid/Unexpected advanced config recieved, retrying"));
|
||||
expectedConfig = false;
|
||||
++_retryConfigCount;
|
||||
}
|
||||
@@ -573,38 +607,27 @@ void NukiWrapper::updateAuthData(bool retrieved)
|
||||
{
|
||||
if(!isPinValid())
|
||||
{
|
||||
Log->println(F("No valid PIN set"));
|
||||
Log->println(F("No valid Nuki Lock PIN set"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!retrieved)
|
||||
{
|
||||
delay(250);
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
Log->print(F("Retrieve log entries: "));
|
||||
result = _nukiLock.retrieveLogEntries(0, _preferences->getInt(preference_authlog_max_entries, MAX_AUTHLOG), 1, false);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
Log->println(result);
|
||||
printCommandResult(result);
|
||||
if(result == Nuki::CmdResult::Success)
|
||||
{
|
||||
@@ -657,28 +680,18 @@ void NukiWrapper::updateKeypad(bool retrieved)
|
||||
|
||||
if(!retrieved)
|
||||
{
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
Log->print(F("Querying lock keypad: "));
|
||||
result = _nukiLock.retrieveKeypadEntries(0, _preferences->getInt(preference_keypad_max_entries, MAX_KEYPAD));
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
printCommandResult(result);
|
||||
@@ -728,28 +741,18 @@ void NukiWrapper::updateTimeControl(bool retrieved)
|
||||
|
||||
if(!retrieved)
|
||||
{
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
Log->print(F("Querying lock time control: "));
|
||||
result = _nukiLock.retrieveTimeControlEntries();
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
printCommandResult(result);
|
||||
@@ -977,7 +980,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
_statusUpdated = true;
|
||||
_network->publishStatusUpdated(_statusUpdated);
|
||||
NukiLock::lockstateToString((NukiLock::LockState)_network->_offState, str);
|
||||
_network->publishString(mqtt_topic_lock_state, str);
|
||||
_network->publishString(mqtt_topic_lock_state, str, true);
|
||||
|
||||
Log->print(F("Lockstate: "));
|
||||
Log->println(str);
|
||||
@@ -997,7 +1000,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Doorsensor state: "));
|
||||
Log->println(str);
|
||||
|
||||
_network->publishString(mqtt_topic_lock_door_sensor_state, str);
|
||||
_network->publishString(mqtt_topic_lock_door_sensor_state, str, true);
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_batteryCritical) == 0)
|
||||
{
|
||||
@@ -1006,7 +1009,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Battery critical: "));
|
||||
Log->println(_network->_offCritical);
|
||||
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_critical, _network->_offCritical);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_critical, _network->_offCritical, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_batteryCharging) == 0)
|
||||
@@ -1016,7 +1019,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Battery charging: "));
|
||||
Log->println(_network->_offCharging);
|
||||
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_charging, _network->_offCharging);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_charging, _network->_offCharging, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_batteryChargeState) == 0)
|
||||
@@ -1026,19 +1029,19 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
Log->print(F("Battery level: "));
|
||||
Log->println(_network->_offChargeState);
|
||||
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishInt(mqtt_topic_battery_level, _network->_offChargeState);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishInt(mqtt_topic_battery_level, _network->_offChargeState, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_keypadBatteryCritical) == 0)
|
||||
{
|
||||
_network->_offKeypadCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_keypad_critical, _network->_offKeypadCritical);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_keypad_critical, _network->_offKeypadCritical, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_doorsensorBatteryCritical) == 0)
|
||||
{
|
||||
_network->_offDoorsensorCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_doorsensor_critical, _network->_offDoorsensorCritical);
|
||||
if(!_preferences->getBool(preference_disable_non_json, false)) _network->publishBool(mqtt_topic_battery_doorsensor_critical, _network->_offDoorsensorCritical, true);
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_commandResponse) == 0)
|
||||
@@ -1068,11 +1071,11 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
|
||||
memset(&str, 0, sizeof(str));
|
||||
lockactionToString((NukiLock::LockAction)_network->_offLockAction, str);
|
||||
_network->publishString(mqtt_topic_lock_last_lock_action, str);
|
||||
_network->publishString(mqtt_topic_lock_last_lock_action, str, true);
|
||||
|
||||
memset(&str, 0, sizeof(str));
|
||||
triggerToString((NukiLock::Trigger)_network->_offTrigger, str);
|
||||
_network->publishString(mqtt_topic_lock_trigger, str);
|
||||
_network->publishString(mqtt_topic_lock_trigger, str, true);
|
||||
|
||||
if(_network->_offAuthId > 0 || _network->_offCodeId > 0)
|
||||
{
|
||||
@@ -1098,7 +1101,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
|
||||
jsonBattery["keypadCritical"] = _network->_offKeypadCritical ? "1" : "0";
|
||||
jsonBattery["doorSensorCritical"] = _network->_offDoorsensorCritical ? "1" : "0";
|
||||
serializeJson(jsonBattery, _resbuf, sizeof(_resbuf));
|
||||
_network->publishString(mqtt_topic_battery_basic_json, _resbuf);
|
||||
_network->publishString(mqtt_topic_battery_basic_json, _resbuf, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1147,16 +1150,6 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
nukiLockPreferences->getBytes(preference_conf_lock_basic_acl, &basicLockConfigAclPrefs, sizeof(basicLockConfigAclPrefs));
|
||||
nukiLockPreferences->getBytes(preference_conf_lock_advanced_acl, &advancedLockConfigAclPrefs, sizeof(advancedLockConfigAclPrefs));
|
||||
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
if(json[basicKeys[i]])
|
||||
@@ -1176,14 +1169,6 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
if(strcmp(basicKeys[i], "name") == 0)
|
||||
{
|
||||
if(strlen(jsonchar) <= 32)
|
||||
@@ -1359,12 +1344,11 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
else jsonResult[basicKeys[i]] = "invalidValue";
|
||||
}
|
||||
|
||||
if(cmdResult != Nuki::CmdResult::Success) {
|
||||
delay(250);
|
||||
if(!cmdResult == Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if(cmdResult == Nuki::CmdResult::Success) basicUpdated = true;
|
||||
@@ -1398,14 +1382,6 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
if(strcmp(advancedKeys[j], "unlockedPositionOffsetDegrees") == 0)
|
||||
{
|
||||
const int16_t keyvalue = atoi(jsonchar);
|
||||
@@ -1653,12 +1629,11 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
else jsonResult[advancedKeys[j]] = "invalidValue";
|
||||
}
|
||||
|
||||
if(cmdResult != Nuki::CmdResult::Success) {
|
||||
delay(250);
|
||||
if(!cmdResult == Nuki::CmdResult::Success) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if(cmdResult == Nuki::CmdResult::Success) advancedUpdated = true;
|
||||
@@ -1673,8 +1648,6 @@ void NukiWrapper::onConfigUpdateReceived(const char *value)
|
||||
}
|
||||
}
|
||||
|
||||
_taskRunning = false;
|
||||
|
||||
nukiLockPreferences->end();
|
||||
|
||||
if(basicUpdated || advancedUpdated) jsonResult["general"] = "success";
|
||||
@@ -1791,14 +1764,6 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
if(strcmp(command, "add") == 0)
|
||||
{
|
||||
if(name == "" || name == "--")
|
||||
@@ -1822,9 +1787,8 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
||||
size_t nameLen = name.length();
|
||||
memcpy(&entry.name, name.c_str(), nameLen > 20 ? 20 : nameLen);
|
||||
entry.code = codeInt;
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.addKeypadEntry(entry);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print("Add keypad code: "); Log->println((int)result);
|
||||
updateKeypad(false);
|
||||
}
|
||||
@@ -1836,9 +1800,8 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
||||
return;
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.deleteKeypadEntry(id);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print("Delete keypad code: "); Log->println((int)result);
|
||||
updateKeypad(false);
|
||||
}
|
||||
@@ -1872,13 +1835,12 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
||||
memcpy(&entry.name, name.c_str(), nameLen > 20 ? 20 : nameLen);
|
||||
entry.code = codeInt;
|
||||
entry.enabled = enabled == 0 ? 0 : 1;
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.updateKeypadEntry(entry);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print("Update keypad code: "); Log->println((int)result);
|
||||
updateKeypad(false);
|
||||
}
|
||||
else if(command == "--")
|
||||
else if(strcmp(command, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1892,8 +1854,6 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if((int)result != -1)
|
||||
@@ -1989,20 +1949,11 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
if(strcmp(action, "delete") == 0) {
|
||||
if(idExists)
|
||||
{
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.deleteKeypadEntry(codeId);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print(F("Delete keypad code: "));
|
||||
Log->println((int)result);
|
||||
}
|
||||
@@ -2188,9 +2139,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
entry.allowedUntilTimeMin = allowedUntilTimeAr[1];
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.addKeypadEntry(entry);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print(F("Add keypad code: "));
|
||||
Log->println((int)result);
|
||||
}
|
||||
@@ -2208,17 +2158,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
return;
|
||||
}
|
||||
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
Nuki::CmdResult resultKp = _nukiLock.retrieveKeypadEntries(0, _preferences->getInt(preference_keypad_max_entries, MAX_KEYPAD));
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
bool foundExisting = false;
|
||||
|
||||
if(resultKp == Nuki::CmdResult::Success)
|
||||
@@ -2346,9 +2287,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
}
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.updateKeypadEntry(entry);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print(F("Update keypad code: "));
|
||||
Log->println((int)result);
|
||||
}
|
||||
@@ -2363,8 +2303,6 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
updateKeypad(false);
|
||||
@@ -2453,20 +2391,11 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
if(strcmp(action, "delete") == 0) {
|
||||
if(idExists)
|
||||
{
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.removeTimeControlEntry(entryId);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print(F("Delete time control: "));
|
||||
Log->println((int)result);
|
||||
}
|
||||
@@ -2525,9 +2454,8 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
|
||||
|
||||
entry.lockAction = timeControlLockAction;
|
||||
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.addTimeControlEntry(entry);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print(F("Add time control: "));
|
||||
Log->println((int)result);
|
||||
}
|
||||
@@ -2539,17 +2467,8 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
|
||||
return;
|
||||
}
|
||||
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
Nuki::CmdResult resultTc = _nukiLock.retrieveTimeControlEntries();
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
bool foundExisting = false;
|
||||
|
||||
if(resultTc == Nuki::CmdResult::Success)
|
||||
@@ -2570,7 +2489,7 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
|
||||
timeAr[0] = entry.timeHour;
|
||||
timeAr[1] = entry.timeMin;
|
||||
}
|
||||
if(lockAction.length() < 1) timeControlLockAction = entry.lockAction;
|
||||
if(lockAction.length() < 1) timeControlLockAction = entry.lockAction;
|
||||
}
|
||||
|
||||
if(!foundExisting)
|
||||
@@ -2599,9 +2518,8 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
|
||||
|
||||
entry.lockAction = timeControlLockAction;
|
||||
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.updateTimeControlEntry(entry);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
Log->print(F("Update time control: "));
|
||||
Log->println((int)result);
|
||||
}
|
||||
@@ -2616,8 +2534,6 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if((int)result != -1)
|
||||
@@ -2658,6 +2574,7 @@ void NukiWrapper::notify(Nuki::EventType eventType)
|
||||
{
|
||||
if(_preferences->getBool(preference_official_hybrid, false) && _intervalHybridLockstate > 0 && millis() > (_intervalHybridLockstate * 1000))
|
||||
{
|
||||
Log->println("OffKeyTurnerStatusUpdated");
|
||||
_statusUpdated = true;
|
||||
_nextHybridLockStateUpdateTs = millis() + _intervalHybridLockstate * 1000;
|
||||
}
|
||||
@@ -2665,6 +2582,7 @@ void NukiWrapper::notify(Nuki::EventType eventType)
|
||||
{
|
||||
if(eventType == Nuki::EventType::KeyTurnerStatusUpdated)
|
||||
{
|
||||
Log->println("KeyTurnerStatusUpdated");
|
||||
_statusUpdated = true;
|
||||
_network->publishStatusUpdated(_statusUpdated);
|
||||
}
|
||||
@@ -2674,29 +2592,22 @@ void NukiWrapper::notify(Nuki::EventType eventType)
|
||||
|
||||
void NukiWrapper::readConfig()
|
||||
{
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
Log->print(F("Reading config. Result: "));
|
||||
result = _nukiLock.requestConfig(&_nukiConfig);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
_nukiConfigValid = result == Nuki::CmdResult::Success;
|
||||
|
||||
Log->print(F("Config valid: "));
|
||||
Log->println(_nukiConfigValid);
|
||||
if(!_nukiConfigValid) {
|
||||
++_retryCount;
|
||||
Log->println("Retrying in 1s");
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
char resultStr[20];
|
||||
@@ -2706,29 +2617,19 @@ void NukiWrapper::readConfig()
|
||||
|
||||
void NukiWrapper::readAdvancedConfig()
|
||||
{
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.requestAdvancedConfig(&_nukiAdvancedConfig);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
_nukiAdvancedConfigValid = result == Nuki::CmdResult::Success;
|
||||
|
||||
if(!_nukiAdvancedConfigValid) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
char resultStr[20];
|
||||
@@ -2760,31 +2661,21 @@ bool NukiWrapper::hasDoorSensor() const
|
||||
|
||||
void NukiWrapper::disableHASS()
|
||||
{
|
||||
if(!_nukiConfigValid) // only ask for config once to save battery life
|
||||
if(!_nukiConfigValid)
|
||||
{
|
||||
Nuki::CmdResult result;
|
||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||
_retryCount = 0;
|
||||
|
||||
while(_retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
int loop = 0;
|
||||
while(_taskRunning && loop < 600)
|
||||
{
|
||||
Log->println("Waiting to run Nuki BLE command");
|
||||
vTaskDelay( 50 / portTICK_PERIOD_MS);
|
||||
++loop;
|
||||
}
|
||||
_taskRunning = true;
|
||||
result = _nukiLock.requestConfig(&_nukiConfig);
|
||||
_taskRunning = false;
|
||||
delay(250);
|
||||
_nukiConfigValid = result == Nuki::CmdResult::Success;
|
||||
|
||||
if(!_nukiConfigValid) {
|
||||
++_retryCount;
|
||||
}
|
||||
else break;
|
||||
|
||||
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user