diff --git a/README.md b/README.md index 798322c..d3bc13a 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ In a browser navigate to the IP address assigned to the ESP32. #### Network Configuration -- Host name: Set the hostname for the Nuki Hub ESP +- Hostname (needs to be unique, "nukihub" is not allowed): Set the hostname for the Nuki Hub ESP, will also be used as the MQTT client ID. Needs to be unique. - Network hardware: "Wi-Fi only" by default, set to one of the specified ethernet modules if available, see the "Supported Ethernet devices" and "[Connecting via Ethernet](#connecting-via-ethernet-optional)" section of this README. - Home Assistant device configuration URL: When using Home Assistant discovery the link to the Nuki Hub Web Configuration will be published to Home Assistant. By default when this setting is left empty this will link to the current IP of the Nuki Hub. When using a reverse proxy to access the Web Configuration you can set a custom URL here. - RSSI Publish interval: Set to a positive integer to set the amount of seconds between updates to the maintenance/wifiRssi MQTT topic with the current Wi-Fi RSSI, set to -1 to disable, default 60. diff --git a/src/Config.h b/src/Config.h index 219041c..e8c976a 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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" diff --git a/src/NukiNetwork.cpp b/src/NukiNetwork.cpp index 8684d4a..acb5aa4 100644 --- a/src/NukiNetwork.cpp +++ b/src/NukiNetwork.cpp @@ -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) { diff --git a/src/WebCfgServer.cpp b/src/WebCfgServer.cpp index 6c9e8a6..576f032 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -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(""); response.print("