diff --git a/README.md b/README.md index ece6b31..72ad344 100644 --- a/README.md +++ b/README.md @@ -324,7 +324,8 @@ Note: All of the following requires the Nuki security code / PIN to be set, see - Add, modify and delete timecontrol entries: Enable to allow configuration of timecontrol entries through MQTT, see the "[Timecontrol](#timecontrol)" section of this README - Publish authorization information: Enable to publish information about authorization entries through MQTT, see the "[Authorization](#authorization)" section of this README - Modify and delete authorization entries: Enable to allow configuration of authorization entries through MQTT, see the "[Authorization](#authorization)" section of this README -- Publish auth data: Enable to publish authorization data to the MQTT topic lock/log +- Publish authorization log: Enable to publish authorization data to the MQTT topic lock/log +- Save auth log number to flash: Enable to save the highest Nuki lock and/or opener auth log number to flash on change. Prevents duplicates in the rolling log but slightly increases flash wear. #### Nuki Lock/Opener Access Control - Enable or disable executing each available lock action for the Nuki Lock and Nuki Opener through MQTT. Note: GPIO control is not restricted through this setting. diff --git a/src/NukiNetworkLock.cpp b/src/NukiNetworkLock.cpp index 6e6a377..16d14e5 100644 --- a/src/NukiNetworkLock.cpp +++ b/src/NukiNetworkLock.cpp @@ -35,8 +35,11 @@ NukiNetworkLock::~NukiNetworkLock() void NukiNetworkLock::initialize() { - _lastRollingLog = _preferences->getInt(preference_lock_log_num, 0); - + if (_preferences->getBool(preference_save_log_num, false)) { + _lastRollingLog = _preferences->getInt(preference_lock_log_num, 0); + _saveLogEnabled = true; + } + String mqttPath = _preferences->getString(preference_mqtt_lock_path, ""); mqttPath.concat("/lock"); @@ -205,8 +208,7 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const return; } - /* - if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last)) + if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last) && !_saveLogEnabled) { if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) @@ -219,7 +221,6 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const _lastRollingLog = atoi(data); } } - */ if(_nukiOfficial->getOffEnabled()) { @@ -774,7 +775,9 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list _lastRollingLog) { _lastRollingLog = log.index; - _preferences->putInt(preference_lock_log_num, _lastRollingLog); + if (_saveLogEnabled) { + _preferences->putInt(preference_lock_log_num, _lastRollingLog); + } serializeJson(entry, _buffer, _bufferSize); _nukiPublisher->publishString(mqtt_topic_lock_log_rolling, _buffer, true); _nukiPublisher->publishInt(mqtt_topic_lock_log_rolling_last, log.index, true); diff --git a/src/NukiNetworkLock.h b/src/NukiNetworkLock.h index dbfa2e0..8ad4994 100644 --- a/src/NukiNetworkLock.h +++ b/src/NukiNetworkLock.h @@ -88,6 +88,7 @@ private: bool _firstTunerStatePublish = true; bool _haEnabled = false; + bool _saveLogEnabled = false; bool _disableNonJSON = false; bool _clearNonJsonKeypad = true; bool _offConnected = false; diff --git a/src/NukiNetworkOpener.cpp b/src/NukiNetworkOpener.cpp index 6685699..2a1750e 100644 --- a/src/NukiNetworkOpener.cpp +++ b/src/NukiNetworkOpener.cpp @@ -23,8 +23,11 @@ NukiNetworkOpener::NukiNetworkOpener(NukiNetwork* network, Preferences* preferen void NukiNetworkOpener::initialize() { - _lastRollingLog = _preferences->getInt(preference_opener_log_num, 0); - + if (_preferences->getBool(preference_save_log_num, false)) { + _lastRollingLog = _preferences->getInt(preference_opener_log_num, 0); + _saveLogEnabled = true; + } + String mqttPath = _preferences->getString(preference_mqtt_lock_path, ""); mqttPath.concat("/opener"); @@ -157,8 +160,7 @@ void NukiNetworkOpener::onMqttDataReceived(const char* topic, byte* payload, con return; } - /* - if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last)) + if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last) && !_saveLogEnabled) { if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) @@ -171,7 +173,6 @@ void NukiNetworkOpener::onMqttDataReceived(const char* topic, byte* payload, con _lastRollingLog = atoi(data); } } - */ if(comparePrefixedPath(topic, mqtt_topic_lock_action)) { @@ -688,7 +689,9 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::listputInt(preference_opener_log_num, _lastRollingLog); + if (_saveLogEnabled) { + _preferences->putInt(preference_opener_log_num, _lastRollingLog); + } } } diff --git a/src/NukiNetworkOpener.h b/src/NukiNetworkOpener.h index d87da6b..a6ac8ad 100644 --- a/src/NukiNetworkOpener.h +++ b/src/NukiNetworkOpener.h @@ -78,6 +78,7 @@ private: char _mqttPath[181] = {0}; bool _firstTunerStatePublish = true; bool _haEnabled = false; + bool _saveLogEnabled = false; bool _disableNonJSON = false; bool _clearNonJsonKeypad = true; diff --git a/src/PreferencesKeys.h b/src/PreferencesKeys.h index 0a726f0..151dff4 100644 --- a/src/PreferencesKeys.h +++ b/src/PreferencesKeys.h @@ -158,6 +158,7 @@ #define preference_mqtt_ca (char*)"mqttca" #define preference_mqtt_crt (char*)"mqttcrt" #define preference_mqtt_key (char*)"mqttkey" +#define preference_save_log_num (char*)"svLgNm" //NOT USER CHANGABLE #define preference_mfa_reconfigure (char*)"mfaRECONF" diff --git a/src/WebCfgServer.cpp b/src/WebCfgServer.cpp index 00ea041..3210136 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -4179,6 +4179,15 @@ bool WebCfgServer::processArgs(PsychicRequest *request, PsychicResponse* resp, S Log->println(key); } } + else if(key == "SAVELOGNUM") + { + if(_preferences->getBool(preference_save_log_num, false) != (value == "1")) + { + _preferences->putBool(preference_save_log_num, (value == "1")); + Log->print("Setting changed: "); + Log->println(key); + } + } else if(key == "CREDDIGEST") { if(_preferences->getInt(preference_http_auth_type, 0) != value.toInt()) @@ -5925,6 +5934,7 @@ esp_err_t WebCfgServer::buildAccLvlHtml(PsychicRequest *request, PsychicResponse printCheckBox(&response, "AUTHPER", "Publish a topic per authorization entry and create HA sensor", _preferences->getBool(preference_auth_topic_per_entry), ""); printCheckBox(&response, "AUTHENA", "Modify and delete authorization entries", _preferences->getBool(preference_auth_control_enabled), ""); printCheckBox(&response, "PUBAUTH", "Publish authorization log", _preferences->getBool(preference_publish_authdata), ""); + printCheckBox(&response, "SAVELOGNUM", "Save auth log number to flash", _preferences->getBool(preference_save_log_num), ""); response.print("
"); response.print("
");