OTA and Debug improvements (#445)
* Use esp_crt_bundle for HTTPS requests * Remove Solo1 support * Improve Nuki device config read functions * Webserial * OTA Improvements * WebCfg fixes * Debug improvements
This commit is contained in:
24
src/Config.h
24
src/Config.h
@@ -16,6 +16,12 @@
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/beta/nuki_hub_updater_esp32c3.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_esp32c3.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_updater_esp32c3.bin"
|
||||
#define GITHUB_LATEST_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_esp32c3.bin"
|
||||
#define GITHUB_LATEST_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_updater_esp32c3.bin"
|
||||
#define GITHUB_BETA_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_esp32c3.bin"
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_updater_esp32c3.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_esp32c3.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_updater_esp32c3.bin"
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
#define GITHUB_LATEST_RELEASE_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/nuki_hub_esp32s3.bin"
|
||||
#define GITHUB_LATEST_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/nuki_hub_updater_esp32s3.bin"
|
||||
@@ -23,6 +29,12 @@
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/beta/nuki_hub_updater_esp32s3.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_esp32s3.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_updater_esp32s3.bin"
|
||||
#define GITHUB_LATEST_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_esp32s3.bin"
|
||||
#define GITHUB_LATEST_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_updater_esp32s3.bin"
|
||||
#define GITHUB_BETA_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_esp32s3.bin"
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_updater_esp32s3.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_esp32s3.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_updater_esp32s3.bin"
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C6)
|
||||
#define GITHUB_LATEST_RELEASE_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/nuki_hub_esp32c6.bin"
|
||||
#define GITHUB_LATEST_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/nuki_hub_updater_esp32c6.bin"
|
||||
@@ -30,6 +42,12 @@
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/beta/nuki_hub_updater_esp32c6.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_esp32c6.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_updater_esp32c6.bin"
|
||||
#define GITHUB_LATEST_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_esp32c6.bin"
|
||||
#define GITHUB_LATEST_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_updater_esp32c6.bin"
|
||||
#define GITHUB_BETA_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_esp32c6.bin"
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_updater_esp32c6.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_esp32c6.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_updater_esp32c6.bin"
|
||||
#else
|
||||
#define GITHUB_LATEST_RELEASE_BINARY_URL "https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/nuki_hub_esp32.bin"
|
||||
#define GITHUB_LATEST_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/nuki_hub_updater_esp32.bin"
|
||||
@@ -37,6 +55,12 @@
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/beta/nuki_hub_updater_esp32.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_esp32.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/master/nuki_hub_updater_esp32.bin"
|
||||
#define GITHUB_LATEST_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_esp32.bin"
|
||||
#define GITHUB_LATEST_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/nuki_hub_updater_esp32.bin"
|
||||
#define GITHUB_BETA_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_esp32.bin"
|
||||
#define GITHUB_BETA_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/beta/nuki_hub_updater_esp32.bin"
|
||||
#define GITHUB_MASTER_RELEASE_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_esp32.bin"
|
||||
#define GITHUB_MASTER_UPDATER_BINARY_URL_DBG (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/debug/master/nuki_hub_updater_esp32.bin"
|
||||
#endif
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
#include <ArduinoJson.h>
|
||||
bool _versionPublished = false;
|
||||
#endif
|
||||
|
||||
NukiNetwork* NukiNetwork::_inst = nullptr;
|
||||
@@ -466,16 +465,16 @@ bool NukiNetwork::update()
|
||||
publishULong(_maintenancePathPrefix, mqtt_topic_uptime, ts / 1000 / 60, true);
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_mqtt_connection_state, "online", true);
|
||||
|
||||
if(_lastMaintenanceTs == 0)
|
||||
{
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_restart_reason_fw, getRestartReason().c_str(), true);
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_restart_reason_esp, getEspRestartReason().c_str(), true);
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_version, NUKI_HUB_VERSION, true);
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_build, NUKI_HUB_BUILD, true);
|
||||
}
|
||||
if(_publishDebugInfo)
|
||||
{
|
||||
publishUInt(_maintenancePathPrefix, mqtt_topic_freeheap, esp_get_free_heap_size(), true);
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_restart_reason_fw, getRestartReason().c_str(), true);
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_restart_reason_esp, getEspRestartReason().c_str(), true);
|
||||
}
|
||||
if (!_versionPublished) {
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_version, NUKI_HUB_VERSION, true);
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_build, NUKI_HUB_BUILD, true);
|
||||
_versionPublished = true;
|
||||
}
|
||||
_lastMaintenanceTs = ts;
|
||||
}
|
||||
@@ -504,13 +503,16 @@ bool NukiNetwork::update()
|
||||
|
||||
if (!jsonError)
|
||||
{
|
||||
_latestVersion = doc["release"]["version"];
|
||||
String currentVersion = NUKI_HUB_VERSION;
|
||||
|
||||
if(atof(doc["release"]["version"]) >= atof(currentVersion.c_str())) _latestVersion = doc["release"]["version"];
|
||||
else if(currentVersion.indexOf("beta") > 0) _latestVersion = doc["beta"]["version"];
|
||||
else if(currentVersion.indexOf("master") > 0) _latestVersion = doc["master"]["version"];
|
||||
else _latestVersion = doc["release"]["version"];
|
||||
|
||||
publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_latest, _latestVersion, true);
|
||||
|
||||
if (_latestVersion != _preferences->getString(preference_latest_version).c_str())
|
||||
{
|
||||
_preferences->putString(preference_latest_version, _latestVersion);
|
||||
}
|
||||
if(strcmp(_latestVersion, _preferences->getString(preference_latest_version).c_str()) != 0) _preferences->putString(preference_latest_version, _latestVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -923,7 +925,11 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
json["avty"]["t"] = availabilityTopic;
|
||||
json["pl_lock"] = lockAction;
|
||||
json["pl_unlk"] = unlockAction;
|
||||
json["pl_open"] = openAction;
|
||||
|
||||
uint32_t aclPrefs[17];
|
||||
_preferences->getBytes(preference_acl, &aclPrefs, sizeof(aclPrefs));
|
||||
if((int)aclPrefs[2]) json["pl_open"] = openAction;
|
||||
|
||||
json["stat_t"] = String("~") + mqtt_topic_lock_ha_state;
|
||||
json["stat_jammed"] = "jammed";
|
||||
json["stat_locked"] = "locked";
|
||||
@@ -1199,6 +1205,38 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
{ { (char*)"en", (char*)"true" },
|
||||
{(char*)"ic", (char*)"mdi:counter"}});
|
||||
|
||||
// Nuki Hub restart reason
|
||||
publishHassTopic("sensor",
|
||||
"nuki_hub_restart_reason",
|
||||
uidString,
|
||||
"_nuki_hub_restart_reason",
|
||||
"Nuki Hub restart reason",
|
||||
name,
|
||||
baseTopic,
|
||||
_lockPath + mqtt_topic_restart_reason_fw,
|
||||
deviceType,
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
"",
|
||||
{ { (char*)"en", (char*)"true" }});
|
||||
|
||||
// Nuki Hub restart reason ESP
|
||||
publishHassTopic("sensor",
|
||||
"nuki_hub_restart_reason_esp",
|
||||
uidString,
|
||||
"_nuki_hub_restart_reason_esp",
|
||||
"Nuki Hub restart reason ESP",
|
||||
name,
|
||||
baseTopic,
|
||||
_lockPath + mqtt_topic_restart_reason_esp,
|
||||
deviceType,
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
"",
|
||||
{ { (char*)"en", (char*)"true" }});
|
||||
|
||||
if(_preferences->getBool(preference_check_updates))
|
||||
{
|
||||
// NUKI Hub latest
|
||||
@@ -1292,7 +1330,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
publishHassTopic("button",
|
||||
"query_lockstate",
|
||||
uidString,
|
||||
"_query_lockstate_button",
|
||||
"_query_lockstate",
|
||||
"Query lock state",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -1309,7 +1347,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
publishHassTopic("button",
|
||||
"query_config",
|
||||
uidString,
|
||||
"_query_config_button",
|
||||
"_query_config",
|
||||
"Query config",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -1326,7 +1364,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
publishHassTopic("button",
|
||||
"query_commandresult",
|
||||
uidString,
|
||||
"_query_commandresult_button",
|
||||
"_query_commandresult",
|
||||
"Query lock state command result",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -1375,7 +1413,7 @@ void NukiNetwork::publishHASSConfigAdditionalLockEntities(char *deviceType, cons
|
||||
publishHassTopic("button",
|
||||
"unlatch",
|
||||
uidString,
|
||||
"_unlatch_button",
|
||||
"_unlatch",
|
||||
"Open",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -1399,7 +1437,7 @@ void NukiNetwork::publishHASSConfigAdditionalLockEntities(char *deviceType, cons
|
||||
publishHassTopic("button",
|
||||
"lockngo",
|
||||
uidString,
|
||||
"_lock_n_go_button",
|
||||
"_lockngo",
|
||||
"Lock 'n' Go",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -1423,7 +1461,7 @@ void NukiNetwork::publishHASSConfigAdditionalLockEntities(char *deviceType, cons
|
||||
publishHassTopic("button",
|
||||
"lockngounlatch",
|
||||
uidString,
|
||||
"_lock_n_go_unlatch_button",
|
||||
"_lockngounlatch",
|
||||
"Lock 'n' Go with unlatch",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -1445,7 +1483,7 @@ void NukiNetwork::publishHASSConfigAdditionalLockEntities(char *deviceType, cons
|
||||
publishHassTopic("button",
|
||||
"query_battery",
|
||||
uidString,
|
||||
"_query_battery_button",
|
||||
"_query_battery",
|
||||
"Query battery",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -2444,7 +2482,7 @@ void NukiNetwork::publishHASSConfigAdditionalOpenerEntities(char *deviceType, co
|
||||
publishHassTopic("button",
|
||||
"unlatch",
|
||||
uidString,
|
||||
"_unlatch_button",
|
||||
"_unlatch",
|
||||
"Open",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -2505,7 +2543,7 @@ void NukiNetwork::publishHASSConfigAdditionalOpenerEntities(char *deviceType, co
|
||||
}
|
||||
|
||||
publishHassTopic("binary_sensor",
|
||||
"ring",
|
||||
"ring_detect",
|
||||
uidString,
|
||||
"_ring_detect",
|
||||
"Ring detect",
|
||||
@@ -3346,7 +3384,7 @@ void NukiNetwork::publishHASSConfigKeypad(char *deviceType, const char *baseTopi
|
||||
publishHassTopic("button",
|
||||
"query_keypad",
|
||||
uidString,
|
||||
"_query_keypad_button",
|
||||
"_query_keypad",
|
||||
"Query keypad",
|
||||
name,
|
||||
baseTopic,
|
||||
@@ -3487,7 +3525,7 @@ void NukiNetwork::removeHASSConfig(char* uidString)
|
||||
removeHassTopic((char*)"button", (char*)"lockngounlatch", uidString);
|
||||
removeHassTopic((char*)"sensor", (char*)"battery_level", uidString);
|
||||
removeHassTopic((char*)"binary_sensor", (char*)"door_sensor", uidString);
|
||||
removeHassTopic((char*)"binary_sensor", (char*)"ring", uidString);
|
||||
removeHassTopic((char*)"binary_sensor", (char*)"ring_detect", uidString);
|
||||
removeHassTopic((char*)"sensor", (char*)"sound_level", uidString);
|
||||
removeHassTopic((char*)"sensor", (char*)"last_action_authorization", uidString);
|
||||
removeHassTopic((char*)"sensor", (char*)"keypad_status", uidString);
|
||||
@@ -3558,6 +3596,8 @@ void NukiNetwork::removeHASSConfig(char* uidString)
|
||||
removeHassTopic((char*)"sensor", (char*)"uptime", uidString);
|
||||
removeHassTopic((char*)"sensor", (char*)"mqtt_log", uidString);
|
||||
removeHassTopic((char*)"binary_sensor", (char*)"hybrid_connected", uidString);
|
||||
removeHassTopic((char*)"sensor", (char*)"nuki_hub_restart_reason", uidString);
|
||||
removeHassTopic((char*)"sensor", (char*)"nuki_hub_restart_reason_esp", uidString);
|
||||
}
|
||||
|
||||
void NukiNetwork::removeHASSConfigTopic(char *deviceType, char *name, char *uidString)
|
||||
|
||||
@@ -196,8 +196,28 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
|
||||
else if(comparePrefixedPath(topic, mqtt_topic_update) && strcmp(value, "1") == 0 && _preferences->getBool(preference_update_from_mqtt, false))
|
||||
{
|
||||
Log->println(F("Update requested via MQTT."));
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_LATEST_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_LATEST_RELEASE_BINARY_URL);
|
||||
String currentVersion = NUKI_HUB_VERSION;
|
||||
|
||||
if(atof(_preferences->getString(preference_latest_version).c_str()) >= atof(currentVersion.c_str()))
|
||||
{
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_LATEST_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_LATEST_RELEASE_BINARY_URL);
|
||||
}
|
||||
else if(currentVersion.indexOf("beta") > 0)
|
||||
{
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_BETA_RELEASE_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_BETA_UPDATER_BINARY_URL);
|
||||
}
|
||||
else if(currentVersion.indexOf("master") > 0)
|
||||
{
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_MASTER_RELEASE_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_MASTER_UPDATER_BINARY_URL);
|
||||
}
|
||||
else
|
||||
{
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_LATEST_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_LATEST_RELEASE_BINARY_URL);
|
||||
}
|
||||
delay(200);
|
||||
restartEsp(RestartReason::OTAReboot);
|
||||
}
|
||||
|
||||
@@ -48,8 +48,9 @@ WebCfgServer::WebCfgServer(NukiNetwork* network, EthServer* ethServer, Preferenc
|
||||
memcpy(&_credPassword, pass, str.length());
|
||||
}
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
_confirmCode = generateConfirmCode();
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
_pinsConfigured = true;
|
||||
|
||||
if(_nuki != nullptr && !_nuki->isPinSet())
|
||||
@@ -312,6 +313,14 @@ void WebCfgServer::initialize()
|
||||
buildOtaHtml(response, _server.arg("errored") != "");
|
||||
_server.send(200, "text/html", response);
|
||||
});
|
||||
_server.on("/otadebug", [&]() {
|
||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||
return _server.requestAuthentication();
|
||||
}
|
||||
String response = "";
|
||||
buildOtaHtml(response, _server.arg("errored") != "", true);
|
||||
_server.send(200, "text/html", response);
|
||||
});
|
||||
_server.on("/reboottoota", [&]() {
|
||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||
return _server.requestAuthentication();
|
||||
@@ -327,29 +336,12 @@ void WebCfgServer::initialize()
|
||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||
return _server.requestAuthentication();
|
||||
}
|
||||
String response = "";
|
||||
String key = _server.argName(0);
|
||||
if(key == "beta")
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest BETA version", 2);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_BETA_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_BETA_RELEASE_BINARY_URL);
|
||||
}
|
||||
else if(key == "master")
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest development version", 2);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_MASTER_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_MASTER_RELEASE_BINARY_URL);
|
||||
}
|
||||
else
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest RELEASE version", 2);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_LATEST_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_LATEST_RELEASE_BINARY_URL);
|
||||
}
|
||||
_server.send(200, "text/html", response);
|
||||
waitAndProcess(true, 1000);
|
||||
restartEsp(RestartReason::OTAReboot);
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
processUpdate();
|
||||
#else
|
||||
_server.sendHeader("Location", "/");
|
||||
_server.send(302, "text/plain", "");
|
||||
#endif
|
||||
});
|
||||
_server.on("/uploadota", HTTP_POST, [&]() {
|
||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||
@@ -401,7 +393,7 @@ void WebCfgServer::update()
|
||||
_server.handleClient();
|
||||
}
|
||||
|
||||
void WebCfgServer::buildOtaHtml(String &response, bool errored)
|
||||
void WebCfgServer::buildOtaHtml(String &response, bool errored, bool debug)
|
||||
{
|
||||
buildHtmlHeader(response);
|
||||
|
||||
@@ -421,20 +413,34 @@ void WebCfgServer::buildOtaHtml(String &response, bool errored)
|
||||
response.concat("<div id=\"autoupdform\"><h4>Update Nuki Hub</h4>");
|
||||
response.concat("Click on the button to reboot and automatically update Nuki Hub and the Nuki Hub updater to the latest versions from GitHub");
|
||||
response.concat("<div style=\"clear: both\"></div>");
|
||||
response.concat("<form onsubmit=\"return confirm('Do you really want to update to the latest release?');\" action=\"/autoupdate\" method=\"get\" style=\"float: left; margin-right: 10px\"><br><input type=\"submit\" style=\"background: green\" value=\"Update to latest release\"></form>");
|
||||
response.concat("<form onsubmit=\"return confirm('Do you really want to update to the latest beta? This version could contain breaking bugs and necessitate downgrading to the latest release version using USB/Serial');\" action=\"/autoupdate\" method=\"get\" style=\"float: left; margin-right: 10px\"><input type=\"hidden\" name=\"beta\" value=\"1\" /><br><input type=\"submit\" style=\"color: black; background: yellow\" value=\"Update to latest beta\"></form>");
|
||||
response.concat("<form onsubmit=\"return confirm('Do you really want to update to the latest development version? This version could contain breaking bugs and necessitate downgrading to the latest release version using USB/Serial');\" action=\"/autoupdate\" method=\"get\" style=\"float: left; margin-right: 10px\"><input type=\"hidden\" name=\"master\" value=\"1\" /><br><input type=\"submit\" style=\"background: red\" value=\"Update to latest development version\"></form>");
|
||||
|
||||
String release_type;
|
||||
|
||||
if(debug) release_type = "debug";
|
||||
else release_type = "release";
|
||||
|
||||
#ifndef DEBUG_NUKIHUB
|
||||
String build_type = "release";
|
||||
#else
|
||||
String build_type = "debug";
|
||||
#endif
|
||||
|
||||
response.concat("<form onsubmit=\"if(document.getElementById('currentver') == document.getElementById('latestver') && \"" + release_type + "\" == \"" + build_type + "\") { alert('You are already on this version, build and build type'); return false; } else { return confirm('Do you really want to update to the latest release?'); } \" action=\"/autoupdate\" method=\"get\" style=\"float: left; margin-right: 10px\"><input type=\"hidden\" name=\"release\" value=\"1\" /><input type=\"hidden\" name=\"" + release_type + "\" value=\"1\" /><input type=\"hidden\" name=\"token\" value=\"" + _confirmCode + "\" /><br><input type=\"submit\" style=\"background: green\" value=\"Update to latest release\"></form>");
|
||||
response.concat("<form onsubmit=\"if(document.getElementById('currentver') == document.getElementById('betaver') && \"" + release_type + "\" == \"" + build_type + "\") { alert('You are already on this version, build and build type'); return false; } else { return confirm('Do you really want to update to the latest beta? This version could contain breaking bugs and necessitate downgrading to the latest release version using USB/Serial'); }\" action=\"/autoupdate\" method=\"get\" style=\"float: left; margin-right: 10px\"><input type=\"hidden\" name=\"beta\" value=\"1\" /><input type=\"hidden\" name=\"" + release_type + "\" value=\"1\" /><input type=\"hidden\" name=\"token\" value=\"" + _confirmCode + "\" /><br><input type=\"submit\" style=\"color: black; background: yellow\" value=\"Update to latest beta\"></form>");
|
||||
response.concat("<form onsubmit=\"if(document.getElementById('currentver') == document.getElementById('devver') && \"" + release_type + "\" == \"" + build_type + "\") { alert('You are already on this version, build and build type'); return false; } else { return confirm('Do you really want to update to the latest development version? This version could contain breaking bugs and necessitate downgrading to the latest release version using USB/Serial'); }\" action=\"/autoupdate\" method=\"get\" style=\"float: left; margin-right: 10px\"><input type=\"hidden\" name=\"master\" value=\"1\" /><input type=\"hidden\" name=\"" + release_type + "\" value=\"1\" /><input type=\"hidden\" name=\"token\" value=\"" + _confirmCode + "\" /><br><input type=\"submit\" style=\"background: red\" value=\"Update to latest development version\"></form>");
|
||||
response.concat("<div style=\"clear: both\"></div><br>");
|
||||
|
||||
response.concat("<b>Current version: </b>");
|
||||
response.concat("<b>Current version: </b><span id=\"currentver\">");
|
||||
response.concat(NUKI_HUB_VERSION);
|
||||
response.concat(" (");
|
||||
response.concat(NUKI_HUB_BUILD);
|
||||
response.concat("), ");
|
||||
response.concat(")</span>, ");
|
||||
response.concat(NUKI_HUB_DATE);
|
||||
response.concat("<br>");
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
bool manifestSuccess = false;
|
||||
|
||||
NetworkClientSecure *client = new NetworkClientSecure;
|
||||
if (client) {
|
||||
client->setDefaultCACertBundle();
|
||||
@@ -454,28 +460,34 @@ void WebCfgServer::buildOtaHtml(String &response, bool errored)
|
||||
|
||||
if (!jsonError)
|
||||
{
|
||||
response.concat("<b>Latest release version: </b>");
|
||||
manifestSuccess = true;
|
||||
response.concat("<b>Latest release version: </b><span id=\"latestver\">");
|
||||
response.concat(doc["release"]["fullversion"].as<const char*>());
|
||||
response.concat(" (");
|
||||
response.concat(doc["release"]["build"].as<const char*>());
|
||||
response.concat("), ");
|
||||
response.concat(")</span>, ");
|
||||
response.concat(doc["release"]["time"].as<const char*>());
|
||||
response.concat("<br>");
|
||||
response.concat("<b>Latest beta version: </b>");
|
||||
response.concat(doc["beta"]["fullversion"].as<const char*>());
|
||||
response.concat("<b>Latest beta version: </b><span id=\"betaver\">");
|
||||
if(doc["beta"]["fullversion"] != "No beta available")
|
||||
{
|
||||
response.concat(doc["beta"]["fullversion"].as<const char*>());
|
||||
response.concat(" (");
|
||||
response.concat(doc["beta"]["build"].as<const char*>());
|
||||
response.concat("), ");
|
||||
response.concat(")</span>, ");
|
||||
response.concat(doc["beta"]["time"].as<const char*>());
|
||||
}
|
||||
else
|
||||
{
|
||||
response.concat(doc["beta"]["fullversion"].as<const char*>());
|
||||
response.concat("</span>");
|
||||
}
|
||||
response.concat("<br>");
|
||||
response.concat("<b>Latest development version: </b>");
|
||||
response.concat("<b>Latest development version: </b><span id=\"devver\">");
|
||||
response.concat(doc["master"]["fullversion"].as<const char*>());
|
||||
response.concat(" (");
|
||||
response.concat(doc["master"]["build"].as<const char*>());
|
||||
response.concat("), ");
|
||||
response.concat(")</span>, ");
|
||||
response.concat(doc["master"]["time"].as<const char*>());
|
||||
response.concat("<br>");
|
||||
}
|
||||
@@ -485,6 +497,11 @@ void WebCfgServer::buildOtaHtml(String &response, bool errored)
|
||||
}
|
||||
delete client;
|
||||
}
|
||||
|
||||
if(!manifestSuccess)
|
||||
{
|
||||
response.concat("<span id=\"currentver\" style=\"display: none;\">currentver</span><span id=\"latestver\" style=\"display: none;\">latestver</span><span id=\"devver\" style=\"display: none;\">devver</span><span id=\"betaver\" style=\"display: none;\">betaver</span>");
|
||||
}
|
||||
#endif
|
||||
response.concat("<br></div>");
|
||||
|
||||
@@ -665,11 +682,20 @@ void WebCfgServer::handleOtaUpload()
|
||||
}
|
||||
}
|
||||
|
||||
void WebCfgServer::buildConfirmHtml(String &response, const String &message, uint32_t redirectDelay)
|
||||
void WebCfgServer::buildConfirmHtml(String &response, const String &message, uint32_t redirectDelay, bool redirect)
|
||||
{
|
||||
String delay(redirectDelay);
|
||||
String header = "<meta http-equiv=\"Refresh\" content=\"" + delay + "; url=/\" />";
|
||||
String header;
|
||||
|
||||
if(!redirect)
|
||||
{
|
||||
String delay(redirectDelay);
|
||||
header = "<meta http-equiv=\"Refresh\" content=\"" + delay + "; url=/\" />";
|
||||
}
|
||||
else
|
||||
{
|
||||
String delay(redirectDelay * 1000);
|
||||
header = "<script type=\"text/JavaScript\">function Redirect() { window.location.href = \"/\"; } setTimeout(function() { Redirect(); }, " + delay + "); </script>";
|
||||
}
|
||||
buildHtmlHeader(response, header);
|
||||
response.concat(message);
|
||||
response.concat("</body></html>");
|
||||
@@ -688,6 +714,12 @@ void WebCfgServer::sendFavicon()
|
||||
_server.send(200, "image/png", (const char*)favicon_32x32, sizeof(favicon_32x32));
|
||||
}
|
||||
|
||||
String WebCfgServer::generateConfirmCode()
|
||||
{
|
||||
int code = random(1000,9999);
|
||||
return String(code);
|
||||
}
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
void WebCfgServer::sendSettings()
|
||||
{
|
||||
@@ -2976,6 +3008,72 @@ void WebCfgServer::processUnpair(bool opener)
|
||||
restartEsp(RestartReason::DeviceUnpaired);
|
||||
}
|
||||
|
||||
void WebCfgServer::processUpdate()
|
||||
{
|
||||
String response = "";
|
||||
String key = _server.argName(0);
|
||||
String key2 = _server.argName(1);
|
||||
String key3 = _server.argName(2);
|
||||
String value3 = _server.arg(2);
|
||||
String key4 = _server.argName(3);
|
||||
|
||||
if(key3 != "token" || value3 != _confirmCode)
|
||||
{
|
||||
buildConfirmHtml(response, "Confirm code is invalid.", 3, true);
|
||||
_server.send(200, "text/html", response);
|
||||
return;
|
||||
}
|
||||
|
||||
if(key == "beta")
|
||||
{
|
||||
if(key2 == "debug")
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest DEBUG BETA version", 2, true);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_BETA_UPDATER_BINARY_URL_DBG);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_BETA_RELEASE_BINARY_URL_DBG);
|
||||
}
|
||||
else
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest BETA version", 2, true);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_BETA_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_BETA_RELEASE_BINARY_URL);
|
||||
}
|
||||
}
|
||||
else if(key == "master")
|
||||
{
|
||||
if(key2 == "debug")
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest DEBUG DEVELOPMENT version", 2, true);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_MASTER_UPDATER_BINARY_URL_DBG);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_MASTER_RELEASE_BINARY_URL_DBG);
|
||||
}
|
||||
else
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest DEVELOPMENT version", 2, true);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_MASTER_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_MASTER_RELEASE_BINARY_URL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(key2 == "debug")
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest DEBUG RELEASE version", 2, true);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_LATEST_UPDATER_BINARY_URL_DBG);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_LATEST_UPDATER_BINARY_URL_DBG);
|
||||
}
|
||||
else
|
||||
{
|
||||
buildConfirmHtml(response, "Rebooting to update Nuki Hub and Nuki Hub updater<br/>Updating to latest RELEASE version", 2, true);
|
||||
_preferences->putString(preference_ota_updater_url, GITHUB_LATEST_UPDATER_BINARY_URL);
|
||||
_preferences->putString(preference_ota_main_url, GITHUB_LATEST_RELEASE_BINARY_URL);
|
||||
}
|
||||
}
|
||||
_server.send(200, "text/html", response);
|
||||
waitAndProcess(true, 1000);
|
||||
restartEsp(RestartReason::OTAReboot);
|
||||
}
|
||||
|
||||
void WebCfgServer::processFactoryReset()
|
||||
{
|
||||
bool resetWifi = false;
|
||||
@@ -3238,13 +3336,6 @@ void WebCfgServer::printParameter(String& response, const char *description, con
|
||||
|
||||
}
|
||||
|
||||
|
||||
String WebCfgServer::generateConfirmCode()
|
||||
{
|
||||
int code = random(1000,9999);
|
||||
return String(code);
|
||||
}
|
||||
|
||||
const std::vector<std::pair<String, String>> WebCfgServer::getNetworkDetectionOptions() const
|
||||
{
|
||||
std::vector<std::pair<String, String>> options;
|
||||
|
||||
@@ -61,6 +61,7 @@ private:
|
||||
void buildConfigureWifiHtml(String& response);
|
||||
void buildInfoHtml(String& response);
|
||||
void processUnpair(bool opener);
|
||||
void processUpdate();
|
||||
void processFactoryReset();
|
||||
void printInputField(String& response, const char* token, const char* description, const char* value, const size_t& maxLength, const char* id, const bool& isPassword = false, const bool& showLengthRestriction = false);
|
||||
void printInputField(String& response, const char* token, const char* description, const int value, size_t maxLength, const char* id);
|
||||
@@ -76,19 +77,18 @@ private:
|
||||
String pinStateToString(uint8_t value);
|
||||
|
||||
void printParameter(String& response, const char* description, const char* value, const char *link = "", const char *id = "");
|
||||
|
||||
String generateConfirmCode();
|
||||
|
||||
NukiWrapper* _nuki = nullptr;
|
||||
NukiOpenerWrapper* _nukiOpener = nullptr;
|
||||
Gpio* _gpio = nullptr;
|
||||
bool _pinsConfigured = false;
|
||||
bool _brokerConfigured = false;
|
||||
String _confirmCode = "----";
|
||||
#endif
|
||||
|
||||
void buildConfirmHtml(String& response, const String &message, uint32_t redirectDelay = 5);
|
||||
void buildOtaHtml(String& response, bool errored);
|
||||
String generateConfirmCode();
|
||||
String _confirmCode = "----";
|
||||
void buildConfirmHtml(String& response, const String &message, uint32_t redirectDelay = 5, bool redirect = false);
|
||||
void buildOtaHtml(String& response, bool errored, bool debug = false);
|
||||
void buildOtaCompletedHtml(String& response);
|
||||
void sendCss();
|
||||
void sendFavicon();
|
||||
|
||||
@@ -78,7 +78,7 @@ void WifiDevice::initialize()
|
||||
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
|
||||
// reduced timeout if ESP is set to restart on disconnect
|
||||
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
|
||||
_wm.setConnectTimeout(5);
|
||||
_wm.setConnectTimeout(20);
|
||||
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
|
||||
_wm.setShowInfoUpdate(false);
|
||||
_wm.setMenu(wm_menu);
|
||||
|
||||
Reference in New Issue
Block a user