Make saving rolling log to flash optional

This commit is contained in:
iranl
2025-09-18 20:14:01 +02:00
parent 0d63211683
commit 30af99308b
7 changed files with 33 additions and 13 deletions

View File

@@ -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.

View File

@@ -35,7 +35,10 @@ NukiNetworkLock::~NukiNetworkLock()
void NukiNetworkLock::initialize()
{
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<NukiLock::LogEntr
if(log.index > _lastRollingLog)
{
_lastRollingLog = log.index;
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);

View File

@@ -88,6 +88,7 @@ private:
bool _firstTunerStatePublish = true;
bool _haEnabled = false;
bool _saveLogEnabled = false;
bool _disableNonJSON = false;
bool _clearNonJsonKeypad = true;
bool _offConnected = false;

View File

@@ -23,7 +23,10 @@ NukiNetworkOpener::NukiNetworkOpener(NukiNetwork* network, Preferences* preferen
void NukiNetworkOpener::initialize()
{
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,9 +689,11 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
}
_lastRollingLog = log.index;
if (_saveLogEnabled) {
_preferences->putInt(preference_opener_log_num, _lastRollingLog);
}
}
}
serializeJson(json, _buffer, _bufferSize);

View File

@@ -78,6 +78,7 @@ private:
char _mqttPath[181] = {0};
bool _firstTunerStatePublish = true;
bool _haEnabled = false;
bool _saveLogEnabled = false;
bool _disableNonJSON = false;
bool _clearNonJsonKeypad = true;

View File

@@ -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"

View File

@@ -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("</table><br>");
response.print("<br><input type=\"submit\" name=\"submit\" value=\"Save\">");