This commit is contained in:
iranl
2024-11-02 19:56:36 +01:00
parent bb50283406
commit b813faf771
6 changed files with 55 additions and 47 deletions

View File

@@ -4,7 +4,7 @@
#define NUKI_HUB_VERSION "9.02"
#define NUKI_HUB_BUILD "unknownbuildnr"
#define NUKI_HUB_DATE "2024-11-01"
#define NUKI_HUB_DATE "2024-11-02"
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"

View File

@@ -607,12 +607,12 @@ bool NukiNetwork::reconnect()
{
_mqttConnectionState = 0;
while (!_device->mqttConnected() && (esp_timer_get_time() / 1000) > _nextReconnect)
while (!_device->mqttConnected() && espMillis() > _nextReconnect)
{
if(strcmp(_mqttBrokerAddr, "") == 0)
{
Log->println(F("MQTT Broker not configured, aborting connection attempt."));
_nextReconnect = (esp_timer_get_time() / 1000) + 5000;
_nextReconnect = espMillis() + 5000;
return false;
}
@@ -634,9 +634,9 @@ bool NukiNetwork::reconnect()
_device->mqttSetServer(_mqttBrokerAddr, _mqttPort);
_device->mqttConnect();
int64_t timeout = (esp_timer_get_time() / 1000) + 60000;
int64_t timeout = espMillis() + 60000;
while(!_connectReplyReceived && (esp_timer_get_time() / 1000) < timeout)
while(!_connectReplyReceived && espMillis() < timeout)
{
delay(50);
_device->update();
@@ -696,7 +696,7 @@ bool NukiNetwork::reconnect()
Log->print(F("MQTT connect failed, rc="));
_device->printError();
_mqttConnectionState = 0;
_nextReconnect = (esp_timer_get_time() / 1000) + 5000;
_nextReconnect = espMillis() + 5000;
//_device->mqttDisconnect(true);
}
}

View File

@@ -278,8 +278,8 @@ void NukiOpenerWrapper::update()
updateKeypad(false);
}
}
if(_checkKeypadCodes && _invalidCount > 0 && ts - 120000 < _lastCodeCheck)
if(_checkKeypadCodes && _invalidCount > 0 && (ts - (120000 * _invalidCount)) > _lastCodeCheck)
{
_invalidCount--;
}
@@ -893,8 +893,8 @@ void NukiOpenerWrapper::updateAuth(bool retrieved)
{
Log->println(F("No valid Nuki Lock PIN set"));
return;
}
}
if(!_preferences->getBool(preference_auth_info_enabled))
{
return;
@@ -2613,14 +2613,14 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
return;
}
if(pow(_invalidCount, 5) + _lastCodeCheck > (esp_timer_get_time() / 1000))
if((pow(_invalidCount, 5) + _lastCodeCheck) > espMillis())
{
_network->publishKeypadJsonCommandResult("checkingCodesBlockedTooManyInvalid");
_lastCodeCheck = (esp_timer_get_time() / 1000);
_lastCodeCheck = espMillis();
return;
}
_lastCodeCheck = (esp_timer_get_time() / 1000);
_lastCodeCheck = espMillis();
if(idExists)
{
@@ -2639,7 +2639,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
{
_invalidCount++;
_network->publishKeypadJsonCommandResult("codeInvalid");
Log->println("Invalid");
Log->print("Invalid\nInvalid count: ");
Log->println(_invalidCount);
return;
}
}
@@ -2647,12 +2648,13 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
{
_invalidCount++;
_network->publishKeypadJsonCommandResult("noExistingCodeIdSet");
Log->print("Invalid count: ");
Log->println(_invalidCount);
return;
}
}
else
{
Nuki::CmdResult result = (Nuki::CmdResult)-1;
int retryCount = 0;
@@ -2732,6 +2734,7 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
}
if(allowedUntil.length() > 0)
{
if(allowedUntil.length() == 19)
{
allowedUntilAr[0] = (uint16_t)allowedUntil.substring(0, 4).toInt();
@@ -2869,7 +2872,7 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
if(resultKp == Nuki::CmdResult::Success)
{
delay(250);
delay(5000);
std::list<NukiOpener::KeypadEntry> entries;
_nukiOpener.getKeypadEntries(&entries);
@@ -3213,7 +3216,7 @@ void NukiOpenerWrapper::onTimeControlCommandReceived(const char *value)
if(resultTc == Nuki::CmdResult::Success)
{
delay(250);
delay(5000);
std::list<NukiOpener::TimeControlEntry> timeControlEntries;
_nukiOpener.getTimeControlEntries(&timeControlEntries);
@@ -3342,7 +3345,7 @@ void NukiOpenerWrapper::onAuthCommandReceived(const char *value)
char oldName[33];
const char *action = json["action"].as<const char*>();
uint16_t authId = json["authId"].as<unsigned int>();
uint32_t authId = json["authId"].as<unsigned int>();
//uint8_t idType = json["idType"].as<unsigned int>();
//unsigned char secretKeyK[32] = {0x00};
uint8_t remoteAllowed;
@@ -3669,7 +3672,7 @@ void NukiOpenerWrapper::onAuthCommandReceived(const char *value)
if(resultAuth == Nuki::CmdResult::Success)
{
delay(250);
delay(5000);
std::list<NukiOpener::AuthorizationEntry> entries;
_nukiOpener.getAuthorizationEntries(&entries);

View File

@@ -431,7 +431,7 @@ void NukiWrapper::update()
_network->clearAuthorizationInfo();
_clearAuthData = false;
}
if(_checkKeypadCodes && _invalidCount > 0 && ts - 120000 < _lastCodeCheck)
if(_checkKeypadCodes && _invalidCount > 0 && (ts - (120000 * _invalidCount)) > _lastCodeCheck)
{
_invalidCount--;
}
@@ -2727,14 +2727,14 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
return;
}
if(pow(_invalidCount, 5) + _lastCodeCheck > (esp_timer_get_time() / 1000))
if((pow(_invalidCount, 5) + _lastCodeCheck) > espMillis())
{
_network->publishKeypadJsonCommandResult("checkingCodesBlockedTooManyInvalid");
_lastCodeCheck = (esp_timer_get_time() / 1000);
_lastCodeCheck = espMillis();
return;
}
_lastCodeCheck = (esp_timer_get_time() / 1000);
_lastCodeCheck = espMillis();
if(idExists)
{
@@ -2753,7 +2753,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
{
_invalidCount++;
_network->publishKeypadJsonCommandResult("codeInvalid");
Log->println("Invalid");
Log->print("Invalid\nInvalid count: ");
Log->println(_invalidCount);
return;
}
}
@@ -2761,6 +2762,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
{
_invalidCount++;
_network->publishKeypadJsonCommandResult("noExistingCodeIdSet");
Log->print("Invalid count: ");
Log->println(_invalidCount);
return;
}
}
@@ -2846,6 +2849,7 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
}
if(allowedUntil.length() > 0)
{
if(allowedUntil.length() == 19)
{
allowedUntilAr[0] = (uint16_t)allowedUntil.substring(0, 4).toInt();
@@ -2983,7 +2987,7 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
if(resultKp == Nuki::CmdResult::Success)
{
delay(250);
delay(5000);
std::list<NukiLock::KeypadEntry> entries;
_nukiLock.getKeypadEntries(&entries);
@@ -3328,7 +3332,7 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
if(resultTc == Nuki::CmdResult::Success)
{
delay(250);
delay(5000);
std::list<NukiLock::TimeControlEntry> timeControlEntries;
_nukiLock.getTimeControlEntries(&timeControlEntries);
@@ -3458,7 +3462,7 @@ void NukiWrapper::onAuthCommandReceived(const char *value)
char oldName[33];
const char *action = json["action"].as<const char*>();
uint16_t authId = json["authId"].as<unsigned int>();
uint32_t authId = json["authId"].as<unsigned int>();
//uint8_t idType = json["idType"].as<unsigned int>();
//unsigned char secretKeyK[32] = {0x00};
uint8_t remoteAllowed;
@@ -3783,11 +3787,11 @@ void NukiWrapper::onAuthCommandReceived(const char *value)
}
Nuki::CmdResult resultAuth = _nukiLock.retrieveAuthorizationEntries(0, _preferences->getInt(preference_auth_max_entries, MAX_AUTH));
delay(250);
bool foundExisting = false;
if(resultAuth == Nuki::CmdResult::Success)
{
delay(5000);
std::list<NukiLock::AuthorizationEntry> entries;
_nukiLock.getAuthorizationEntries(&entries);

View File

@@ -3389,15 +3389,15 @@ esp_err_t WebCfgServer::buildCredHtml(PsychicRequest *request)
PsychicStreamResponse response(request, "text/plain");
response.beginSend();
buildHtmlHeader(&response);
response.print("<form class=\"adapt\" method=\"post\" action=\"savecfg\">");
response.print("<form id=\"credfrm\" class=\"adapt\" onsubmit=\"return testcreds();\" method=\"post\" action=\"savecfg\">");
response.print("<h3>Credentials</h3>");
response.print("<table>");
printInputField(&response, "CREDUSER", "User (# to clear)", _preferences->getString(preference_cred_user).c_str(), 30, "", false, true);
printInputField(&response, "CREDPASS", "Password", "*", 30, "", true, true);
printInputField(&response, "CREDPASSRE", "Retype password", "*", 30, "", true);
printInputField(&response, "CREDUSER", "User (# to clear)", _preferences->getString(preference_cred_user).c_str(), 30, "id=\"inputuser\"", false, true);
printInputField(&response, "CREDPASS", "Password", "*", 30, "id=\"inputpass\"", true, true);
printInputField(&response, "CREDPASSRE", "Retype password", "*", 30, "id=\"inputpass2\"", true);
response.print("</table>");
response.print("<br><input type=\"submit\" name=\"submit\" value=\"Save\">");
response.print("</form><script>function testcreds() { var input_user = document.getElementById(\"inputuser\").value; var input_pass = document.getElementById(\"inputpass\").value; var pattern = /^[ -~]*$/; if(!pattern.test(input_user) || !pattern.test(input_pass)) { alert('Only non unicode characters are allowed in username and password'); return false;} else { return true; } }</script>");
response.print("</form><script>function testcreds() { var input_user = document.getElementById(\"inputuser\").value; var input_pass = document.getElementById(\"inputpass\").value; var input_pass2 = document.getElementById(\"inputpass2\").value; var pattern = /^[ -~]*$/; if(input_user == '#' || input_user == '') { return true; } if (input_pass != input_pass2) { alert('Passwords do not match'); return false;} if(!pattern.test(input_user) || !pattern.test(input_pass)) { alert('Only non unicode characters are allowed in username and password'); return false;} else { return true; } }</script>");
if(_nuki != nullptr)
{
response.print("<br><br><form class=\"adapt\" method=\"post\" action=\"savecfg\">");