Unique hostname and disable MDNS
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#define NUKI_HUB_VERSION "9.10"
|
||||
#define NUKI_HUB_VERSION_INT (uint32_t)910
|
||||
#define NUKI_HUB_BUILD "unknownbuildnr"
|
||||
#define NUKI_HUB_DATE "2025-03-21"
|
||||
#define NUKI_HUB_DATE "2025-04-01"
|
||||
|
||||
#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"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#endif
|
||||
#include "networkDevices/EthernetDevice.h"
|
||||
#include "hal/wdt_hal.h"
|
||||
#include "esp_mac.h"
|
||||
|
||||
NukiNetwork* NukiNetwork::_inst = nullptr;
|
||||
|
||||
@@ -216,9 +217,15 @@ void NukiNetwork::initialize()
|
||||
{
|
||||
_hostname = _preferences->getString(preference_hostname, "");
|
||||
|
||||
if(_hostname == "")
|
||||
if(_hostname == "" || _hostname == "nukihub")
|
||||
{
|
||||
_hostname = "nukihub";
|
||||
char _nukiHubUidString[20];
|
||||
uint8_t mac[8];
|
||||
esp_efuse_mac_get_default(mac);
|
||||
uint64_t curDevId;
|
||||
memcpy(&curDevId, &mac, 8);
|
||||
sprintf(_nukiHubUidString, "%" PRIu64, curDevId);
|
||||
_hostname = (String)"NH" + _nukiHubUidString;
|
||||
_preferences->putString(preference_hostname, _hostname);
|
||||
}
|
||||
|
||||
@@ -258,9 +265,15 @@ void NukiNetwork::initialize()
|
||||
|
||||
_hostname = _preferences->getString(preference_hostname, "");
|
||||
|
||||
if(_hostname == "")
|
||||
if(_hostname == "" || _hostname == "nukihub")
|
||||
{
|
||||
_hostname = "nukihub";
|
||||
char _nukiHubUidString[20];
|
||||
uint8_t mac[8];
|
||||
esp_efuse_mac_get_default(mac);
|
||||
uint64_t curDevId;
|
||||
memcpy(&curDevId, &mac, 8);
|
||||
sprintf(_nukiHubUidString, "%" PRIu64, curDevId);
|
||||
_hostname = (String)"NH" + _nukiHubUidString;
|
||||
_preferences->putString(preference_hostname, _hostname);
|
||||
}
|
||||
|
||||
@@ -429,7 +442,7 @@ bool NukiNetwork::update()
|
||||
_firstDisconnected = true;
|
||||
}
|
||||
|
||||
if(!_device->mqttConnected() && _device->isConnected())
|
||||
if(!_logIp && _device->isConnected() && !_device->mqttConnected() )
|
||||
{
|
||||
bool success = reconnect();
|
||||
if(!success)
|
||||
@@ -453,7 +466,7 @@ bool NukiNetwork::update()
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
if(!_device->mqttConnected() || !_device->isConnected())
|
||||
if(!_device->isConnected() || !_device->mqttConnected() )
|
||||
{
|
||||
if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000)
|
||||
{
|
||||
|
||||
@@ -3174,7 +3174,7 @@ bool WebCfgServer::processArgs(PsychicRequest *request, PsychicResponse* resp, S
|
||||
}
|
||||
else if(key == "HOSTNAME")
|
||||
{
|
||||
if(_preferences->getString(preference_hostname, "") != value)
|
||||
if(_preferences->getString(preference_hostname, "") != value && value != "nukihub")
|
||||
{
|
||||
_preferences->putString(preference_hostname, value);
|
||||
Log->print("Setting changed: ");
|
||||
@@ -5104,7 +5104,7 @@ esp_err_t WebCfgServer::buildNetworkConfigHtml(PsychicRequest *request, PsychicR
|
||||
response.print("<input type=\"hidden\" name=\"page\" value=\"savecfg\">");
|
||||
response.print("<h3>Network Configuration</h3>");
|
||||
response.print("<table>");
|
||||
printInputField(&response, "HOSTNAME", "Host name", _preferences->getString(preference_hostname).c_str(), 100, "");
|
||||
printInputField(&response, "HOSTNAME", "Hostname (needs to be unique, \"nukihub\" is not allowed)", _preferences->getString(preference_hostname).c_str(), 100, "");
|
||||
printDropDown(&response, "NWHW", "Network hardware", String(_preferences->getInt(preference_network_hardware)), getNetworkDetectionOptions(), "");
|
||||
printInputField(&response, "HASSCUURL", "Home Assistant device configuration URL (empty to use http://LOCALIP; fill when using a reverse proxy for example)", _preferences->getString(preference_mqtt_hass_cu_url).c_str(), 261, "");
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
|
||||
39
src/main.cpp
39
src/main.cpp
@@ -95,6 +95,8 @@ RTC_NOINIT_ATTR bool wifiFallback;
|
||||
RTC_NOINIT_ATTR bool ethCriticalFailure;
|
||||
bool coredumpPrinted = true;
|
||||
bool timeSynced = false;
|
||||
bool webStarted = false;
|
||||
bool webSSLStarted = false;
|
||||
|
||||
int lastHTTPeventId = -1;
|
||||
bool doOta = false;
|
||||
@@ -218,7 +220,7 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
|
||||
{
|
||||
SPIFFS.remove((String)"/" + file.name());
|
||||
}
|
||||
|
||||
|
||||
file = root.openNextFile();
|
||||
}
|
||||
}
|
||||
@@ -257,6 +259,20 @@ void networkTask(void *pvParameters)
|
||||
{
|
||||
esp_netif_sntp_start();
|
||||
}
|
||||
|
||||
/* MDNS currently disabled for causing issues (9.10 / 2025-04-01)
|
||||
if(webSSLStarted) {
|
||||
if (MDNS.begin(preferences->getString(preference_hostname, "nukihub").c_str())) {
|
||||
MDNS.addService("http", "tcp", 443);
|
||||
}
|
||||
}
|
||||
else if(webStarted) {
|
||||
if (MDNS.begin(preferences->getString(preference_hostname, "nukihub").c_str())) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
reroute = false;
|
||||
setReroute();
|
||||
}
|
||||
@@ -529,6 +545,8 @@ void setupTasks(bool ota)
|
||||
esp_chip_info_t info;
|
||||
esp_chip_info(&info);
|
||||
uint8_t espCores = info.cores;
|
||||
Log->print("Cores: ");
|
||||
Log->println(espCores);
|
||||
|
||||
if(ota)
|
||||
{
|
||||
@@ -673,7 +691,7 @@ void setup()
|
||||
{
|
||||
logCoreDump();
|
||||
}
|
||||
|
||||
|
||||
if (SPIFFS.begin(true))
|
||||
{
|
||||
listDir(SPIFFS, "/", 1);
|
||||
@@ -792,10 +810,7 @@ void setup()
|
||||
return response->redirect("/");
|
||||
});
|
||||
psychicSSLServer->begin();
|
||||
if (MDNS.begin(preferences->getString(preference_hostname, "nukihub").c_str())) {
|
||||
MDNS.addService("http", "tcp", 443);
|
||||
}
|
||||
|
||||
webSSLStarted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -812,9 +827,7 @@ void setup()
|
||||
return response->redirect("/");
|
||||
});
|
||||
psychicServer->begin();
|
||||
if (MDNS.begin(preferences->getString(preference_hostname, "nukihub").c_str())) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
webStarted = true;
|
||||
#ifdef CONFIG_SOC_SPIRAM_SUPPORTED
|
||||
}
|
||||
#endif
|
||||
@@ -977,9 +990,7 @@ void setup()
|
||||
return response->redirect("/");
|
||||
});
|
||||
psychicSSLServer->begin();
|
||||
if (MDNS.begin(preferences->getString(preference_hostname, "nukihub").c_str())) {
|
||||
MDNS.addService("http", "tcp", 443);
|
||||
}
|
||||
webSSLStarted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -996,9 +1007,7 @@ void setup()
|
||||
return response->redirect("/");
|
||||
});
|
||||
psychicServer->begin();
|
||||
if (MDNS.begin(preferences->getString(preference_hostname, "nukihub").c_str())) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
webStarted = true;
|
||||
#ifdef CONFIG_SOC_SPIRAM_SUPPORTED
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -286,10 +286,6 @@ void WifiDevice::onWifiEvent(const WiFiEvent_t &event, const WiFiEventInfo_t &in
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Log->println("Connected to access point");
|
||||
if(!_openAP)
|
||||
{
|
||||
onConnected();
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Log->println("Disconnected from WiFi access point");
|
||||
|
||||
Reference in New Issue
Block a user