add option to unpair nuki
This commit is contained in:
@@ -144,6 +144,12 @@ void NukiWrapper::setPin(const uint16_t pin)
|
|||||||
_nukiBle.saveSecurityPincode(pin);
|
_nukiBle.saveSecurityPincode(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NukiWrapper::unpair()
|
||||||
|
{
|
||||||
|
_nukiBle.unPairNuki();
|
||||||
|
_paired = false;
|
||||||
|
}
|
||||||
|
|
||||||
void NukiWrapper::updateKeyTurnerState()
|
void NukiWrapper::updateKeyTurnerState()
|
||||||
{
|
{
|
||||||
_nukiBle.requestKeyTurnerState(&_keyTurnerState);
|
_nukiBle.requestKeyTurnerState(&_keyTurnerState);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public:
|
|||||||
|
|
||||||
void setPin(const uint16_t pin);
|
void setPin(const uint16_t pin);
|
||||||
|
|
||||||
|
void unpair();
|
||||||
|
|
||||||
const Nuki::KeyTurnerState& keyTurnerState();
|
const Nuki::KeyTurnerState& keyTurnerState();
|
||||||
const bool isPaired();
|
const bool isPaired();
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define nuki_hub_version "2.4"
|
#define nuki_hub_version "2.5"
|
||||||
@@ -10,6 +10,8 @@ WebCfgServer::WebCfgServer(NukiWrapper* nuki, Network* network, EthServer* ethSe
|
|||||||
_preferences(preferences),
|
_preferences(preferences),
|
||||||
_allowRestartToPortal(allowRestartToPortal)
|
_allowRestartToPortal(allowRestartToPortal)
|
||||||
{
|
{
|
||||||
|
_confirmCode = generateConfirmCode();
|
||||||
|
|
||||||
String str = _preferences->getString(preference_cred_user);
|
String str = _preferences->getString(preference_cred_user);
|
||||||
|
|
||||||
if(str.length() > 0)
|
if(str.length() > 0)
|
||||||
@@ -51,6 +53,13 @@ void WebCfgServer::initialize()
|
|||||||
buildConfigureWifiHtml(response);
|
buildConfigureWifiHtml(response);
|
||||||
_server.send(200, "text/html", response);
|
_server.send(200, "text/html", response);
|
||||||
});
|
});
|
||||||
|
_server.on("/unpair", [&]() {
|
||||||
|
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||||
|
return _server.requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
|
processUnpair();
|
||||||
|
});
|
||||||
_server.on("/wifimanager", [&]() {
|
_server.on("/wifimanager", [&]() {
|
||||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||||
return _server.requestAuthentication();
|
return _server.requestAuthentication();
|
||||||
@@ -320,6 +329,15 @@ void WebCfgServer::buildCredHtml(String &response)
|
|||||||
response.concat("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
|
response.concat("<br><INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Save\">");
|
||||||
response.concat("</FORM>");
|
response.concat("</FORM>");
|
||||||
|
|
||||||
|
_confirmCode = generateConfirmCode();
|
||||||
|
response.concat("<br><br><h3>Unpair NUKI</h3>");
|
||||||
|
response.concat("<form method=\"get\" action=\"/unpair\">");
|
||||||
|
String message = "Type ";
|
||||||
|
message.concat(_confirmCode);
|
||||||
|
message.concat(" to confirm unpair");
|
||||||
|
printInputField(response, "CONFIRMTOKEN", message.c_str(), "", 10);
|
||||||
|
response.concat("<br><br><button type=\"submit\">OK</button>");
|
||||||
|
|
||||||
response.concat("</BODY>\n");
|
response.concat("</BODY>\n");
|
||||||
response.concat("</HTML>\n");
|
response.concat("</HTML>\n");
|
||||||
}
|
}
|
||||||
@@ -357,6 +375,42 @@ void WebCfgServer::buildConfigureWifiHtml(String &response)
|
|||||||
response.concat("</HTML>\n");
|
response.concat("</HTML>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printInputField(response, "CONFIRMTOKEN", "Type confirm", "", 10);
|
||||||
|
|
||||||
|
|
||||||
|
//int count = _server.args();
|
||||||
|
//for(int index = 0; index < count; index++)
|
||||||
|
//{
|
||||||
|
//String key = _server.argName(index);
|
||||||
|
//String value = _server.arg(index);
|
||||||
|
void WebCfgServer::processUnpair()
|
||||||
|
{
|
||||||
|
String response = "";
|
||||||
|
if(_server.args() == 0)
|
||||||
|
{
|
||||||
|
buildConfirmHtml(response, "Confirm code is invalid.", 3);
|
||||||
|
_server.send(200, "text/html", response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String key = _server.argName(0);
|
||||||
|
String value = _server.arg(0);
|
||||||
|
|
||||||
|
if(key != "CONFIRMTOKEN" || value != _confirmCode)
|
||||||
|
{
|
||||||
|
buildConfirmHtml(response, "Confirm code is invalid.", 3);
|
||||||
|
_server.send(200, "text/html", response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildConfirmHtml(response, "Unpairing NUKI and restarting.", 3);
|
||||||
|
_server.send(200, "text/html", response);
|
||||||
|
_nuki->unpair();
|
||||||
|
waitAndProcess(false, 1000);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
void WebCfgServer::buildHtmlHeader(String &response)
|
void WebCfgServer::buildHtmlHeader(String &response)
|
||||||
{
|
{
|
||||||
@@ -438,6 +492,13 @@ void WebCfgServer::printParameter(String& response, const char *description, con
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String WebCfgServer::generateConfirmCode()
|
||||||
|
{
|
||||||
|
int code = random(1000,9999);
|
||||||
|
return String(code);
|
||||||
|
}
|
||||||
|
|
||||||
void WebCfgServer::waitAndProcess(const bool blocking, const uint32_t duration)
|
void WebCfgServer::waitAndProcess(const bool blocking, const uint32_t duration)
|
||||||
{
|
{
|
||||||
unsigned long timeout = millis() + duration;
|
unsigned long timeout = millis() + duration;
|
||||||
@@ -454,3 +515,4 @@ void WebCfgServer::waitAndProcess(const bool blocking, const uint32_t duration)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ private:
|
|||||||
void buildCredHtml(String& response);
|
void buildCredHtml(String& response);
|
||||||
void buildConfirmHtml(String& response, const String &message, uint32_t redirectDelay = 5);
|
void buildConfirmHtml(String& response, const String &message, uint32_t redirectDelay = 5);
|
||||||
void buildConfigureWifiHtml(String& response);
|
void buildConfigureWifiHtml(String& response);
|
||||||
|
void processUnpair();
|
||||||
|
|
||||||
void buildHtmlHeader(String& response);
|
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 char* value, const size_t maxLength, const bool isPassword = false);
|
||||||
@@ -41,6 +42,7 @@ private:
|
|||||||
|
|
||||||
void printParameter(String& response, const char* description, const char* value);
|
void printParameter(String& response, const char* description, const char* value);
|
||||||
|
|
||||||
|
String generateConfirmCode();
|
||||||
void waitAndProcess(const bool blocking, const uint32_t duration);
|
void waitAndProcess(const bool blocking, const uint32_t duration);
|
||||||
|
|
||||||
WebServer _server;
|
WebServer _server;
|
||||||
@@ -53,5 +55,7 @@ private:
|
|||||||
char _credPassword[20] = {0};
|
char _credPassword[20] = {0};
|
||||||
bool _allowRestartToPortal = false;
|
bool _allowRestartToPortal = false;
|
||||||
|
|
||||||
|
String _confirmCode = "----";
|
||||||
|
|
||||||
bool _enabled = true;
|
bool _enabled = true;
|
||||||
};
|
};
|
||||||
Binary file not shown.
Reference in New Issue
Block a user