allow to enable publishing auth data in web interface

This commit is contained in:
technyon
2022-05-06 22:40:09 +02:00
parent b14c83384e
commit 8a1d7e7523
5 changed files with 63 additions and 23 deletions

View File

@@ -42,6 +42,7 @@ void NukiWrapper::initialize()
_intervalLockstate = _preferences->getInt(preference_query_interval_lockstate);
_intervalBattery = _preferences->getInt(preference_query_interval_battery);
_publishAuthData = _preferences->getBool(preference_publish_authdata);
if(_intervalLockstate == 0)
{
@@ -59,7 +60,14 @@ void NukiWrapper::initialize()
Serial.print(F("Lock state interval: "));
Serial.print(_intervalLockstate);
Serial.print(F(" | Battery interval: "));
Serial.println(_intervalBattery);
Serial.print(_intervalBattery);
Serial.print(F(" | Publish auth data: "));
Serial.println(_publishAuthData ? "yes" : "no");
if(!_publishAuthData)
{
_clearAuthData = true;
}
}
void NukiWrapper::update()
@@ -101,11 +109,6 @@ void NukiWrapper::update()
_nextConfigUpdateTs = ts + _intervalConfig * 1000;
updateConfig();
}
if(_nextLogUpdateTs == 0 || ts > _nextLogUpdateTs)
{
_nextLogUpdateTs = ts + 10 * 1000;
updateAuthInfo();
}
if(_nextLockAction != (Nuki::LockAction)0xff)
{
@@ -126,6 +129,12 @@ void NukiWrapper::update()
}
}
if(_clearAuthData)
{
_network->publishAuthorizationInfo(0, "");
_clearAuthData = false;
}
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(Nuki::KeyTurnerState));
}
@@ -147,22 +156,15 @@ void NukiWrapper::updateKeyTurnerState()
Serial.println(lockStateStr);
}
updateAuthInfo();
if(_publishAuthData)
{
updateAuthData();
}
}
void NukiWrapper::updateBatteryState()
{
_nukiBle.requestBatteryReport(&_batteryReport);
/*
Serial.print(F("Voltage: ")); Serial.println(_batteryReport.batteryVoltage);
Serial.print(F("Drain: ")); Serial.println(_batteryReport.batteryDrain);
Serial.print(F("Resistance: ")); Serial.println(_batteryReport.batteryResistance);
Serial.print(F("Max Current: ")); Serial.println(_batteryReport.maxTurnCurrent);
Serial.print(F("Crit. State: ")); Serial.println(_batteryReport.criticalBatteryState);
Serial.print(F("Lock Dist: ")); Serial.println(_batteryReport.lockDistance);
*/
_network->publishBatteryReport(_batteryReport);
}
@@ -174,13 +176,12 @@ void NukiWrapper::updateConfig()
_network->publishAdvancedConfig(_nukiAdvancedConfig);
}
void NukiWrapper::updateAuthInfo()
void NukiWrapper::updateAuthData()
{
return;
Nuki::CmdResult result = _nukiBle.retrieveLogEntries(0, 0, 0, true);
if(result != Nuki::CmdResult::Success)
{
_network->publishAuthorizationInfo(0, "");
return;
}
vTaskDelay( 100 / portTICK_PERIOD_MS);
@@ -188,6 +189,7 @@ void NukiWrapper::updateAuthInfo()
result = _nukiBle.retrieveLogEntries(_nukiBle.getLogEntryCount() - 2, 1, 0, false);
if(result != Nuki::CmdResult::Success)
{
_network->publishAuthorizationInfo(0, "");
return;
}
vTaskDelay( 200 / portTICK_PERIOD_MS);
@@ -206,6 +208,10 @@ void NukiWrapper::updateAuthInfo()
_lastAuthId = entry.authId;
}
}
else
{
_network->publishAuthorizationInfo(0, "");
}
}
//struct __attribute__((packed)) LogEntry {

View File

@@ -32,7 +32,7 @@ private:
void updateKeyTurnerState();
void updateBatteryState();
void updateConfig();
void updateAuthInfo();
void updateAuthData();
void readConfig();
void readAdvancedConfig();
@@ -47,6 +47,8 @@ private:
int _intervalLockstate = 0; // seconds
int _intervalBattery = 0; // seconds
int _intervalConfig = 60 * 60; // seconds
bool _publishAuthData = false;
bool _clearAuthData = false;
Nuki::KeyTurnerState _lastKeyTurnerState;
Nuki::KeyTurnerState _keyTurnerState;
@@ -66,7 +68,6 @@ private:
unsigned long _nextLockStateUpdateTs = 0;
unsigned long _nextBatteryReportTs = 0;
unsigned long _nextConfigUpdateTs = 0;
unsigned long _nextLogUpdateTs = 0;
unsigned long _nextPairTs = 0;
Nuki::LockAction _nextLockAction = (Nuki::LockAction)0xff;
};

View File

@@ -11,6 +11,7 @@
#define preference_query_interval_battery "batInterval"
#define preference_cred_user "crdusr"
#define preference_cred_password "crdpass"
#define preference_publish_authdata "pubauth"
#define preference_presence_detection_timeout "prdtimeout"
#define preference_has_mac_saved "hasmac"
#define preference_has_mac_byte_0 "macb0"

View File

@@ -98,6 +98,8 @@ bool WebCfgServer::processArgs(String& message)
bool clearMqttCredentials = false;
bool clearCredentials = false;
bool publishAuthData = false;
int count = _server.args();
for(int index = 0; index < count; index++)
{
@@ -159,6 +161,10 @@ bool WebCfgServer::processArgs(String& message)
_preferences->putInt(preference_presence_detection_timeout, value.toInt());
configChanged = true;
}
else if(key == "PUBAUTH")
{
publishAuthData = true;
}
else if(key == "CREDUSER")
{
if(value == "#")
@@ -191,6 +197,12 @@ bool WebCfgServer::processArgs(String& message)
}
}
if(_preferences->getBool(preference_publish_authdata) != publishAuthData)
{
_preferences->putBool(preference_publish_authdata, publishAuthData);
configChanged = true;
}
if(clearMqttCredentials)
{
_preferences->putString(preference_mqtt_user, "");
@@ -255,6 +267,7 @@ void WebCfgServer::buildHtml(String& response)
printInputField(response, "HOSTNAME", "Host name", _preferences->getString(preference_hostname).c_str(), 100);
printInputField(response, "LSTINT", "Query interval lock state (seconds)", _preferences->getInt(preference_query_interval_lockstate), 10);
printInputField(response, "BATINT", "Query interval battery (seconds)", _preferences->getInt(preference_query_interval_battery), 10);
printCheckBox(response, "PUBAUTH", "Publish auth data", _preferences->getBool(preference_publish_authdata));
printInputField(response, "PRDTMO", "Presence detection timeout (seconds, -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);
response.concat("</table>");
@@ -372,7 +385,7 @@ void WebCfgServer::printInputField(String& response,
response.concat(token);
response.concat("\" SIZE=\"25\" MAXLENGTH=\"");
response.concat(maxLengthStr);
response.concat("\\\">");
response.concat("\\\"/>");
response.concat("</td>");
response.concat("</tr>");
}
@@ -388,6 +401,24 @@ void WebCfgServer::printInputField(String& response,
printInputField(response, token, description, valueStr, maxLength);
}
void WebCfgServer::printCheckBox(String &response, const char *token, const char *description, const bool value)
{
response.concat("<tr>");
response.concat("<td>");
response.concat(description);
response.concat("</td>");
response.concat("<td>");
response.concat(" <INPUT TYPE=");
response.concat("checkbox ");
response.concat("NAME=\"");
response.concat(token);
response.concat("\"");
response.concat(value ? " checked=\"checked\"" : "");
response.concat(" />");
response.concat("</td>");
response.concat("</tr>");
}
void WebCfgServer::printParameter(String& response, const char *description, const char *value)
{
response.concat("<tr>");

View File

@@ -37,6 +37,7 @@ private:
void buildHtmlHeader(String& response);
void printInputField(String& response, const char* token, const char* description, const char* value, const size_t maxLength, const bool isPassword = false);
void printInputField(String& response, const char* token, const char* description, const int value, size_t maxLength);
void printCheckBox(String& response, const char* token, const char* description, const bool value);
void printParameter(String& response, const char* description, const char* value);