add option to restart device if no ble beacons received

This commit is contained in:
technyon
2022-12-17 19:17:02 +01:00
parent b625e284c7
commit 658ee409c8
7 changed files with 36 additions and 2 deletions

View File

@@ -40,6 +40,7 @@ void NukiOpenerWrapper::initialize()
_intervalLockstate = _preferences->getInt(preference_query_interval_lockstate);
_intervalBattery = _preferences->getInt(preference_query_interval_battery);
_publishAuthData = _preferences->getBool(preference_publish_authdata);
_restartBeaconTimeout = _preferences->getInt(preference_restart_ble_beacon_lost);
if(_intervalLockstate == 0)
{
@@ -84,11 +85,20 @@ void NukiOpenerWrapper::update()
}
else
{
vTaskDelay( 200 / portTICK_PERIOD_MS);
delay(200);
return;
}
}
if(_restartBeaconTimeout > 0 && (millis() - _nukiOpener.getLastReceivedBeaconTs() > _restartBeaconTimeout * 1000))
{
Serial.print("No BLE beacon received from the opener for ");
Serial.print((millis() - _nukiOpener.getLastReceivedBeaconTs()) / 1000);
Serial.println(" seconds, restarting device.");
delay(200);
ESP.restart();
}
_nukiOpener.updateConnectionState();
unsigned long ts = millis();

View File

@@ -53,6 +53,7 @@ private:
int _intervalLockstate = 0; // seconds
int _intervalBattery = 0; // seconds
int _intervalConfig = 60 * 60; // seconds
int _restartBeaconTimeout = 0; // seconds
bool _publishAuthData = false;
bool _clearAuthData = false;

View File

@@ -45,6 +45,7 @@ void NukiWrapper::initialize()
_keypadEnabled = _preferences->getBool(preference_keypad_control_enabled);
_publishAuthData = _preferences->getBool(preference_publish_authdata);
_maxKeypadCodeCount = _preferences->getUInt(preference_max_keypad_code_count);
_restartBeaconTimeout = _preferences->getInt(preference_restart_ble_beacon_lost);
if(_intervalLockstate == 0)
{
@@ -61,6 +62,11 @@ void NukiWrapper::initialize()
_intervalKeypad = 60 * 30;
_preferences->putInt(preference_query_interval_keypad, _intervalKeypad);
}
if(_restartBeaconTimeout < 10)
{
_restartBeaconTimeout = -1;
_preferences->putInt(preference_restart_ble_beacon_lost, _restartBeaconTimeout);
}
_nukiLock.setEventHandler(this);
@@ -103,6 +109,15 @@ void NukiWrapper::update()
}
}
if(_restartBeaconTimeout > 0 && (millis() - _nukiLock.getLastReceivedBeaconTs() > _restartBeaconTimeout * 1000))
{
Serial.print("No BLE beacon received from the lock for ");
Serial.print((millis() - _nukiLock.getLastReceivedBeaconTs()) / 1000);
Serial.println(" seconds, restarting device.");
delay(200);
ESP.restart();
}
_nukiLock.updateConnectionState();
unsigned long ts = millis();

View File

@@ -59,6 +59,7 @@ private:
int _intervalBattery = 0; // seconds
int _intervalConfig = 60 * 60; // seconds
int _intervalKeypad = 0; // seconds
int _restartBeaconTimeout = 0; // seconds
bool _publishAuthData = false;
bool _clearAuthData = false;
std::vector<uint16_t> _keypadCodeIds;

View File

@@ -19,6 +19,7 @@
#define preference_network_timeout "nettmout"
#define preference_restart_on_disconnect "restdisc"
#define preference_restart_timer "resttmr"
#define preference_restart_ble_beacon_lost "rstbcn"
#define preference_query_interval_lockstate "lockStInterval"
#define preference_query_interval_battery "batInterval"
#define preference_query_interval_keypad "kpInterval"

View File

@@ -1,3 +1,3 @@
#pragma once
#define nuki_hub_version "6.3"
#define nuki_hub_version "6.4"

View File

@@ -301,6 +301,11 @@ bool WebCfgServer::processArgs(String& message)
_preferences->putInt(preference_presence_detection_timeout, value.toInt());
configChanged = true;
}
else if(key == "RSBC")
{
_preferences->putInt(preference_restart_ble_beacon_lost, value.toInt());
configChanged = true;
}
else if(key == "PUBAUTH")
{
_preferences->putBool(preference_publish_authdata, (value == "1"));
@@ -622,6 +627,7 @@ void WebCfgServer::buildNukiConfigHtml(String &response)
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));
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
printInputField(response, "RSBC", "Restart if bluetooth beacons not received (seconds; -1 to disable)", _preferences->getInt(preference_restart_ble_beacon_lost), 10);
response.concat("</table>");
response.concat("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
response.concat("</FORM>");