fix retry counter
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#define mqtt_topic_lock_action "/lock/action"
|
||||
#define mqtt_topic_lock_rssi "/lock/rssi"
|
||||
#define mqtt_topic_lock_address "/lock/address"
|
||||
#define mqtt_topic_lock_retry "/lock/retry"
|
||||
|
||||
#define mqtt_topic_config_button_enabled "/configuration/buttonEnabled"
|
||||
#define mqtt_topic_config_led_enabled "/configuration/ledEnabled"
|
||||
|
||||
@@ -388,6 +388,11 @@ void NetworkLock::publishRssi(const int& rssi)
|
||||
publishInt(mqtt_topic_lock_rssi, rssi);
|
||||
}
|
||||
|
||||
void NetworkLock::publishRetry(const std::string& message)
|
||||
{
|
||||
publishString(mqtt_topic_lock_retry, message.c_str());
|
||||
}
|
||||
|
||||
void NetworkLock::publishBleAddress(const std::string &address)
|
||||
{
|
||||
publishString(mqtt_topic_lock_address, address.c_str());
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
void publishConfig(const NukiLock::Config& config);
|
||||
void publishAdvancedConfig(const NukiLock::AdvancedConfig& config);
|
||||
void publishRssi(const int& rssi);
|
||||
void publishRetry(const std::string& message);
|
||||
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 removeHASSConfig(char* uidString);
|
||||
|
||||
@@ -185,6 +185,7 @@ void NukiWrapper::update()
|
||||
|
||||
if(cmdResult == Nuki::CmdResult::Success)
|
||||
{
|
||||
_retryCount = 0;
|
||||
_nextLockAction = (NukiLock::LockAction) 0xff;
|
||||
if (_intervalLockstate > 10)
|
||||
{
|
||||
@@ -193,27 +194,28 @@ void NukiWrapper::update()
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_retryCount == -1)
|
||||
if(_retryCount < _nrOfRetries)
|
||||
{
|
||||
_retryCount = _nrOfRetries;
|
||||
Log->print(F("Last command failed, retrying after "));
|
||||
Log->print(_retryDelay);
|
||||
Log->print(F(" milliseconds. Retry "));
|
||||
Log->print(_retryCount + 1);
|
||||
Log->print(" of ");
|
||||
Log->println(_nrOfRetries);
|
||||
|
||||
_network->publishRetry(std::to_string(_retryCount + 1));
|
||||
|
||||
_nextLockStateUpdateTs = millis() + _retryDelay;
|
||||
|
||||
++_retryCount;
|
||||
}
|
||||
else if(_retryCount == 0)
|
||||
else
|
||||
{
|
||||
Log->println(F("Maximum number of retries exceeded, aborting."));
|
||||
_network->publishRetry("failed");
|
||||
_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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ private:
|
||||
uint _maxKeypadCodeCount = 0;
|
||||
int _nrOfRetries = 0;
|
||||
int _retryDelay = 0;
|
||||
int _retryCount = -1;
|
||||
int _retryCount = 0;
|
||||
unsigned long _nextLockStateUpdateTs = 0;
|
||||
unsigned long _nextBatteryReportTs = 0;
|
||||
unsigned long _nextConfigUpdateTs = 0;
|
||||
|
||||
Reference in New Issue
Block a user