add retry mechanic
This commit is contained in:
@@ -48,6 +48,14 @@ void NukiWrapper::initialize()
|
|||||||
_maxKeypadCodeCount = _preferences->getUInt(preference_max_keypad_code_count);
|
_maxKeypadCodeCount = _preferences->getUInt(preference_max_keypad_code_count);
|
||||||
_restartBeaconTimeout = _preferences->getInt(preference_restart_ble_beacon_lost);
|
_restartBeaconTimeout = _preferences->getInt(preference_restart_ble_beacon_lost);
|
||||||
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
|
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
|
||||||
|
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries);
|
||||||
|
_retryDelay = _preferences->getInt(preference_command_retry_delay);
|
||||||
|
|
||||||
|
if(_retryDelay <= 100)
|
||||||
|
{
|
||||||
|
_retryDelay = 100;
|
||||||
|
_preferences->putInt(preference_command_retry_delay, _retryDelay);
|
||||||
|
}
|
||||||
|
|
||||||
if(_intervalLockstate == 0)
|
if(_intervalLockstate == 0)
|
||||||
{
|
{
|
||||||
@@ -175,12 +183,39 @@ void NukiWrapper::update()
|
|||||||
Log->print(F("Lock action result: "));
|
Log->print(F("Lock action result: "));
|
||||||
Log->println(resultStr);
|
Log->println(resultStr);
|
||||||
|
|
||||||
|
if(cmdResult == Nuki::CmdResult::Success)
|
||||||
|
{
|
||||||
_nextLockAction = (NukiLock::LockAction) 0xff;
|
_nextLockAction = (NukiLock::LockAction) 0xff;
|
||||||
if (_intervalLockstate > 10)
|
if (_intervalLockstate > 10)
|
||||||
{
|
{
|
||||||
_nextLockStateUpdateTs = ts + 10 * 1000;
|
_nextLockStateUpdateTs = ts + 10 * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(_retryCount == -1)
|
||||||
|
{
|
||||||
|
_retryCount = _nrOfRetries;
|
||||||
|
}
|
||||||
|
else if(_retryCount == 0)
|
||||||
|
{
|
||||||
|
_nextLockAction = (NukiLock::LockAction) 0xff;
|
||||||
|
_retryCount = -1;
|
||||||
|
if (_intervalLockstate > 10)
|
||||||
|
{
|
||||||
|
_nextLockStateUpdateTs = ts + 10 * 1000;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log->print(F("Last command failed, retrying after "));
|
||||||
|
Log->print(_retryDelay);
|
||||||
|
Log->print(F(" milliseconds."));
|
||||||
|
|
||||||
|
--_retryCount;
|
||||||
|
_nextLockStateUpdateTs = millis() + _retryDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(_clearAuthData)
|
if(_clearAuthData)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ private:
|
|||||||
bool _keypadEnabled = false;
|
bool _keypadEnabled = false;
|
||||||
bool _configRead = false;
|
bool _configRead = false;
|
||||||
uint _maxKeypadCodeCount = 0;
|
uint _maxKeypadCodeCount = 0;
|
||||||
|
int _nrOfRetries = 0;
|
||||||
|
int _retryDelay = 0;
|
||||||
|
int _retryCount = -1;
|
||||||
unsigned long _nextLockStateUpdateTs = 0;
|
unsigned long _nextLockStateUpdateTs = 0;
|
||||||
unsigned long _nextBatteryReportTs = 0;
|
unsigned long _nextBatteryReportTs = 0;
|
||||||
unsigned long _nextConfigUpdateTs = 0;
|
unsigned long _nextConfigUpdateTs = 0;
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#define preference_query_interval_keypad "kpInterval"
|
#define preference_query_interval_keypad "kpInterval"
|
||||||
#define preference_keypad_control_enabled "kpEnabled"
|
#define preference_keypad_control_enabled "kpEnabled"
|
||||||
#define preference_register_as_app "regAsApp" // true = register as hub; false = register as app
|
#define preference_register_as_app "regAsApp" // true = register as hub; false = register as app
|
||||||
|
#define preference_command_nr_of_retries "nrRetry"
|
||||||
|
#define preference_command_retry_delay "nrRetry"
|
||||||
#define preference_cred_user "crdusr"
|
#define preference_cred_user "crdusr"
|
||||||
#define preference_cred_password "crdpass"
|
#define preference_cred_password "crdpass"
|
||||||
#define preference_publish_authdata "pubauth"
|
#define preference_publish_authdata "pubauth"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define nuki_hub_version "6.10"
|
#define nuki_hub_version "6.10-retry-1"
|
||||||
@@ -307,6 +307,16 @@ bool WebCfgServer::processArgs(String& message)
|
|||||||
_preferences->putBool(preference_keypad_control_enabled, (value == "1"));
|
_preferences->putBool(preference_keypad_control_enabled, (value == "1"));
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
|
else if(key == "NRTRY")
|
||||||
|
{
|
||||||
|
_preferences->putInt(preference_command_nr_of_retries, value.toInt());
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
|
else if(key == "TRYDLY")
|
||||||
|
{
|
||||||
|
_preferences->putInt(preference_command_retry_delay, value.toInt());
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
else if(key == "PRDTMO")
|
else if(key == "PRDTMO")
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_presence_detection_timeout, value.toInt());
|
_preferences->putInt(preference_presence_detection_timeout, value.toInt());
|
||||||
@@ -637,6 +647,8 @@ void WebCfgServer::buildNukiConfigHtml(String &response)
|
|||||||
printInputField(response, "KPINT", "Query interval keypad (seconds)", _preferences->getInt(preference_query_interval_keypad), 10);
|
printInputField(response, "KPINT", "Query interval keypad (seconds)", _preferences->getInt(preference_query_interval_keypad), 10);
|
||||||
printCheckBox(response, "KPENA", "Enabled keypad control via MQTT", _preferences->getBool(preference_keypad_control_enabled));
|
printCheckBox(response, "KPENA", "Enabled keypad control via MQTT", _preferences->getBool(preference_keypad_control_enabled));
|
||||||
}
|
}
|
||||||
|
printInputField(response, "NRTRY", "Number of retries if command failed", _preferences->getInt(preference_command_nr_of_retries), 10);
|
||||||
|
printInputField(response, "TRYDLY", "Delay between retries", _preferences->getInt(preference_command_retry_delay), 10);
|
||||||
printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata));
|
printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata));
|
||||||
printCheckBox(response, "GPLCK", "Enable control via GPIO", _preferences->getBool(preference_gpio_locking_enabled));
|
printCheckBox(response, "GPLCK", "Enable control via GPIO", _preferences->getBool(preference_gpio_locking_enabled));
|
||||||
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
|
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user