From 2509b1c5d5a6e697e5e18a05885def37e0bc71a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Mon, 21 Jul 2025 12:16:32 +0200 Subject: [PATCH] New hostname handling - add option to enable mDNS in settings - move hostname to "nw" key in config JSON - add new config key in "nw" for mDNS (bool) - remove `prepareHostname()` function - update mDNS calls - add hostname update for Ethernet - move WiFi configuration to cfg.json - rename LED and WiFi to Hardware and Network in settings - reorder network settings --- wled00/cfg.cpp | 38 +++++++----- wled00/data/settings.htm | 6 +- wled00/data/settings_ui.htm | 8 +-- wled00/data/settings_wifi.htm | 110 ++++++++++++++++++---------------- wled00/data/style.css | 2 +- wled00/fcn_declare.h | 2 +- wled00/improv.cpp | 9 ++- wled00/network.cpp | 23 +++++-- wled00/set.cpp | 32 +++++----- wled00/util.cpp | 27 --------- wled00/wled.cpp | 25 ++------ wled00/wled.h | 3 +- wled00/wled_server.cpp | 2 +- wled00/xml.cpp | 11 ++-- 14 files changed, 143 insertions(+), 155 deletions(-) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 712cf2058..ac10b85d7 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -57,25 +57,22 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { #endif JsonObject id = doc["id"]; - getStringFromJson(cmDNS, id[F("mdns")], sizeof(cmDNS)); - // fill in unique mDNS name if not set (cmDNS can be empty meaning no mDNS is used) - if (strcmp(cmDNS, DEFAULT_MDNS_NAME) == 0) sprintf_P(cmDNS, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6); - getStringFromJson(serverDescription, id[F("name")], sizeof(serverDescription)); - if (!fromFS) { - char hostname[25]; - prepareHostname(hostname, sizeof(hostname)-1); - #ifdef ARDUINO_ARCH_ESP32 - WiFi.setHostname(hostname); - #else - WiFi.hostname(hostname); - #endif + // legacy behaviour + getStringFromJson(hostName, id[F("mdns")], sizeof(hostName)); + if (strlen(hostName) == 0) { + mDNSenabled = false; // if no host name is set, disable mDNS + sprintf_P(hostName, PSTR("wled-%.*s"), 6, escapedMac.c_str() + 6); } + + getStringFromJson(serverDescription, id["name"], sizeof(serverDescription)); #ifndef WLED_DISABLE_ALEXA getStringFromJson(alexaInvocationName, id[F("inv")], sizeof(alexaInvocationName)); #endif CJSON(simplifiedUI, id[F("sui")]); JsonObject nw = doc["nw"]; + CJSON(mDNSenabled, nw[F("mdns")]); + getStringFromJson(hostName, nw["name"], sizeof(hostName)); #ifndef WLED_DISABLE_ESPNOW CJSON(enableESPNow, nw[F("espnow")]); linked_remotes.clear(); @@ -154,13 +151,23 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { JsonObject wifi = doc[F("wifi")]; noWifiSleep = !(wifi[F("sleep")] | !noWifiSleep); // inverted - //noWifiSleep = !noWifiSleep; CJSON(force802_3g, wifi[F("phy")]); //force phy mode g? #ifdef ARDUINO_ARCH_ESP32 CJSON(txPower, wifi[F("txpwr")]); txPower = min(max((int)txPower, (int)WIFI_POWER_2dBm), (int)WIFI_POWER_19_5dBm); #endif + // apply WiFi options from above (regardless of fromFS or not) +#ifdef ARDUINO_ARCH_ESP32 + WiFi.setSleep(!noWifiSleep); + WiFi.setHostname(hostName); + WiFi.setTxPower(wifi_power_t(txPower)); +#else + WiFi.setPhyMode(force802_3g ? WIFI_PHY_MODE_11G : WIFI_PHY_MODE_11N); + wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); + WiFi.hostname(hostName); +#endif + JsonObject hw = doc[F("hw")]; // initialize LED pins and lengths prior to other HW (except for ethernet) @@ -837,14 +844,15 @@ void serializeConfig(JsonObject root) { root[F("vid")] = VERSION; JsonObject id = root.createNestedObject("id"); - id[F("mdns")] = cmDNS; - id[F("name")] = serverDescription; + id["name"] = serverDescription; #ifndef WLED_DISABLE_ALEXA id[F("inv")] = alexaInvocationName; #endif id[F("sui")] = simplifiedUI; JsonObject nw = root.createNestedObject("nw"); + id["name"] = hostName; + id[F("mdns")] = mDNSenabled; #ifndef WLED_DISABLE_ESPNOW nw[F("espnow")] = enableESPNow; JsonArray lrem = nw.createNestedArray(F("linked_remote")); diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm index 82c778214..aa4201bb5 100644 --- a/wled00/data/settings.htm +++ b/wled00/data/settings.htm @@ -38,13 +38,13 @@ - - + + - + diff --git a/wled00/data/settings_ui.htm b/wled00/data/settings_ui.htm index cb7ded7e6..7e65f0b40 100644 --- a/wled00/data/settings_ui.htm +++ b/wled00/data/settings_ui.htm @@ -155,14 +155,13 @@ function Save() { SetLS(); - if (d.Sf.DS.value != initial_ds || /*d.Sf.ST.checked != initial_st ||*/ d.Sf.SU.checked != initial_su) d.Sf.submit(); + if (d.Sf.DS.value != initial_ds || d.Sf.SU.checked != initial_su) d.Sf.submit(); } function S() { getLoc(); loadJS(getURL('/settings/s.js?p=3'), false, undefined, ()=>{ initial_ds = d.Sf.DS.value; - //initial_st = d.Sf.ST.checked; initial_su = d.Sf.SU.checked; GetLS(); }); // If we set async false, file is loaded and executed, then next statement is processed @@ -219,10 +218,9 @@

Web Setup

- Server description:
- + Device name:
Enable simplified UI:
- The following UI customization settings are unique both to the WLED device and this browser.
+ The following UI customization settings are unique both to the WLED device and this browser.
You will need to set them again if using a different browser, device or WLED IP address.
Refresh the main UI to apply changes.

diff --git a/wled00/data/settings_wifi.htm b/wled00/data/settings_wifi.htm index e4a63dd59..63d14a7f3 100644 --- a/wled00/data/settings_wifi.htm +++ b/wled00/data/settings_wifi.htm @@ -3,7 +3,7 @@ - WiFi Settings + Network Settings @@ -189,14 +190,15 @@ Static subnet mask:

-

WiFi setup

- Hostname/mDNS address (empty for no mDNS):
- http://.local
+

Network setup

+ Hostname
+
+ Enable mDNS:
+
http://wled.local
Client IP: Not connected
-

Connect to existing network

+

WiFi


- Wireless networks

@@ -204,20 +206,59 @@ Static subnet mask:
DNS server address:
...
-

Configure Access Point

- AP SSID (empty for no AP):

+
+

Access Point

+ AP SSID (empty for no AP):

Hide AP name:
- AP password (empty for open):

+ AP password (empty for open):

Access Point WiFi channel:
- AP opens: + AP opens:

- AP IP: Not active
+ AP IP: Not active
+
+
+

Ethernet Type

+
+ ESP-NOW is incompatible with Ethernet. +
+
+

ESP-NOW Wireless

+
+ This firmware build does not include ESP-NOW support.
+
+
+ Enable ESP-NOW:
+ Listen for events over ESP-NOW
+ Keep disabled if not using a remote or wireless sync, increases power consumption.
+
+ Last device seen: +
+ Linked MACs:
+
+
+ +
+

Experimental

Force 802.11g mode (ESP8266 only):
Disable WiFi sleep:
@@ -238,43 +279,6 @@ Static subnet mask:

WARNING: Modifying TX power may render device unreachable. - -

ESP-NOW Wireless

-
- This firmware build does not include ESP-NOW support.
-
-
- Enable ESP-NOW:
- Listen for events over ESP-NOW
- Keep disabled if not using a remote or ESP-NOW sync, increases power consumption.
-
- Last device seen: None -
- Linked MACs (10 max):
-
-
-
-
- -
-

Ethernet Type

-
- ESP-NOW is incompatible with Ethernet. -

diff --git a/wled00/data/style.css b/wled00/data/style.css index b6cb0f9e6..d33f69341 100644 --- a/wled00/data/style.css +++ b/wled00/data/style.css @@ -64,7 +64,7 @@ button.sml { .hide { display: none; } -.err { +.err, input:invalid { color: #f00; } .warn { diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index f2fea119c..a646eb268 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -371,6 +371,7 @@ void espNowReceiveCB(uint8_t* address, uint8_t* data, uint8_t len, signed int rs //network.cpp bool initEthernet(); // result is informational int getSignalQuality(int rssi); +IPAddress resolveHostname(const String &hostname, bool useMDNS = true); void fillMAC2Str(char *str, const uint8_t *mac); void fillStr2MAC(uint8_t *mac, const char *str); int findWiFi(bool doScan = false); @@ -505,7 +506,6 @@ size_t printSetFormValue(Print& settingsScript, const char* key, int val); size_t printSetFormValue(Print& settingsScript, const char* key, const char* val); size_t printSetFormIndex(Print& settingsScript, const char* key, int index); size_t printSetClassElementHTML(Print& settingsScript, const char* key, const int index, const char* val); -void prepareHostname(char* hostname, size_t maxLen = 32); [[gnu::pure]] bool isAsterisksOnly(const char* str, byte maxLen); bool requestJSONBufferLock(uint8_t moduleID=255); void releaseJSONBufferLock(); diff --git a/wled00/improv.cpp b/wled00/improv.cpp index 0bc7a6698..6adc179c5 100644 --- a/wled00/improv.cpp +++ b/wled00/improv.cpp @@ -206,11 +206,10 @@ void sendImprovInfoResponse() { #endif strlwr(bString); #endif - //Use serverDescription if it has been changed from the default "WLED", else mDNS name - bool useMdnsName = (strcmp(serverDescription, "WLED") == 0 && strlen(cmDNS) > 0); - char vString[32]; - sprintf_P(vString, PSTR("%s/%i"), versionString, VERSION); - const char *str[4] = {"WLED", vString, bString, useMdnsName ? cmDNS : serverDescription}; + char vString[33]; + snprintf_P(vString, sizeof(vString)-1, PSTR("%s/%i"), versionString, VERSION); + //Use serverDescription if it has been changed from the default "WLED", else host name + const char *str[4] = {"WLED", vString, bString, strcmp(serverDescription, "WLED") == 0 ? hostName : serverDescription}; sendImprovRPCResult(ImprovRPCType::Request_Info, 4, str); } diff --git a/wled00/network.cpp b/wled00/network.cpp index d06ce2b46..fbbb04ff7 100644 --- a/wled00/network.cpp +++ b/wled00/network.cpp @@ -265,6 +265,24 @@ int getSignalQuality(int rssi) } +IPAddress resolveHostname(const String &hostname, bool useMDNS) { + IPAddress clnt; + if (Network.isConnected() && hostname.length() > 0) { + #ifdef ARDUINO_ARCH_ESP32 + if (mDNSenabled && useMDNS) { + String mDNSname = hostname; + mDNSname.toLowerCase(); // make sure we have a lowercase hostname + int pos = mDNSname.indexOf(F(".local")); + if (pos > 0) mDNSname.remove(pos); // remove .local domain if present (and anything following it) + if (mDNSname.indexOf('.') < 0) clnt = MDNS.queryHost(mDNSname.c_str()); + } + #endif + if (clnt == IPAddress()) WiFi.hostByName(hostname.c_str(), clnt); // use full hostname if MDNS failed + } + return clnt; +} + +// fill MAC address string with 6 bytes from mac array void fillMAC2Str(char *str, const uint8_t *mac) { sprintf_P(str, PSTR("%02x%02x%02x%02x%02x%02x"), MAC2STR(mac)); byte nul = 0; @@ -396,15 +414,12 @@ void WiFiEvent(WiFiEvent_t event) if (!apActive) { WiFi.disconnect(true); // disable WiFi entirely } + ETH.setHostname(hostName); if (multiWiFi[0].staticIP != (uint32_t)0x00000000 && multiWiFi[0].staticGW != (uint32_t)0x00000000) { ETH.config(multiWiFi[0].staticIP, multiWiFi[0].staticGW, multiWiFi[0].staticSN, dnsAddress); } else { ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); } - // convert the "serverDescription" into a valid DNS hostname (alphanumeric) - char hostname[33]; - prepareHostname(hostname, sizeof(hostname)-1); - ETH.setHostname(hostname); showWelcomePage = false; break; } diff --git a/wled00/set.cpp b/wled00/set.cpp index 742e69371..e9dc3aa65 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -63,14 +63,17 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) dnsAddress = IPAddress(request->arg(F("D0")).toInt(),request->arg(F("D1")).toInt(),request->arg(F("D2")).toInt(),request->arg(F("D3")).toInt()); } - strlcpy(cmDNS, request->arg(F("CM")).c_str(), sizeof(cmDNS)); - char hostname[25]; - prepareHostname(hostname, sizeof(hostname)-1); + strlcpy(hostName, request->arg(F("CM")).c_str(), sizeof(hostName)); + if (strlen(hostName) == 0) sprintf_P(hostName, PSTR("wled-%.*s"), 6, escapedMac.c_str() + 6); // hostname must not be empty #ifdef ARDUINO_ARCH_ESP32 - WiFi.setHostname(hostname); + #ifdef WLED_USE_ETHERNET + ETH.setHostname(hostName); + #endif + WiFi.setHostname(hostName); #else - WiFi.hostname(hostname); + WiFi.hostname(hostName); #endif + mDNSenabled = request->hasArg(F("MD")); apBehavior = request->arg(F("AB")).toInt(); char oldSSID[33]; strcpy(oldSSID, apSSID); @@ -89,10 +92,17 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) #ifdef ARDUINO_ARCH_ESP32 int tx = request->arg(F("TX")).toInt(); txPower = min(max(tx, (int)WIFI_POWER_2dBm), (int)WIFI_POWER_19_5dBm); + WiFi.setTxPower(wifi_power_t(txPower)); #endif force802_3g = request->hasArg(F("FG")); noWifiSleep = request->hasArg(F("WS")); + #ifdef ARDUINO_ARCH_ESP32 + WiFi.setSleep(!noWifiSleep); + #else + WiFi.setPhyMode(force802_3g ? WIFI_PHY_MODE_11G : WIFI_PHY_MODE_11N); + wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); + #endif #ifndef WLED_DISABLE_ESPNOW bool oldESPNow = enableESPNow; @@ -279,8 +289,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) disablePullUp = (bool)request->hasArg(F("IP")); touchThreshold = request->arg(F("TT")).toInt(); - for (int i = 0; i < WLED_MAX_BUTTONS; i++) { - int offset = i < 10 ? '0' : 'A' - 10; + for (unsigned i = 0; i < WLED_MAX_BUTTONS; i++) { + unsigned offset = i < 10 ? '0' : 'A' - 10; char bt[4] = "BT"; bt[2] = offset+i; bt[3] = 0; // button pin (use A,B,C,... if WLED_MAX_BUTTONS>10) char be[4] = "BE"; be[2] = offset+i; be[3] = 0; // button type (use A,B,C,... if WLED_MAX_BUTTONS>10) int hw_btn_pin = request->arg(bt).toInt(); @@ -375,14 +385,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) if (subPage == SUBPAGE_UI) { strlcpy(serverDescription, request->arg(F("DS")).c_str(), 33); - char hostname[25]; - prepareHostname(hostname, sizeof(hostname)-1); - #ifdef ARDUINO_ARCH_ESP32 - WiFi.setHostname(hostname); - #else - WiFi.hostname(hostname); - #endif - //syncToggleReceive = request->hasArg(F("ST")); simplifiedUI = request->hasArg(F("SU")); DEBUG_PRINTLN(F("Enumerating ledmaps")); enumerateLedmaps(); diff --git a/wled00/util.cpp b/wled00/util.cpp index 7f41102b9..eecd52732 100644 --- a/wled00/util.cpp +++ b/wled00/util.cpp @@ -114,33 +114,6 @@ size_t printSetClassElementHTML(Print& settingsScript, const char* key, const in } -// prepare a unique hostname based on the last 6 digits of the MAC address -// if no mDNS name or serverDescription is set, otherwise use cmDNS or serverDescription -// the hostname will be at most 24 characters long, starting with "wled-" -// and containing only alphanumeric characters and hyphens -// the hostname will not end with a hyphen and will be null-terminated -void prepareHostname(char* hostname, size_t maxLen) -{ - // create a unique hostname based on the last 6 digits of the MAC address if no mDNS name or serverDescription is set - sprintf_P(hostname, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6); - const char *pC = cmDNS; // use cmDNS as hostname if set - if (strlen(pC) == 0) pC = serverDescription; // else use serverDescription - unsigned pos = 5; // keep "wled-" from unique name - while (*pC && pos < maxLen) { // while !null and not over length - if (isalnum(*pC)) { // if the current char is alpha-numeric append it to the hostname - hostname[pos++] = *pC; - } else if (*pC == ' ' || *pC == '_' || *pC == '-' || *pC == '+' || *pC == '!' || *pC == '?' || *pC == '*') { - hostname[pos++] = '-'; - } - // else do nothing - no leading hyphens and do not include hyphens for all other characters. - pC++; - } - // last character must not be hyphen - while (pos > 4 && hostname[pos-1] == '-') pos--; - hostname[pos] = '\0'; // terminate string (leave at least "wled") -} - - bool isAsterisksOnly(const char* str, byte maxLen) { for (unsigned i = 0; i < maxLen; i++) { diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 63af7c2b8..adedde531 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -138,7 +138,7 @@ void WLED::loop() yield(); #ifdef ESP8266 - MDNS.update(); + if (mDNSenabled) MDNS.update(); #endif //millis() rolls over every 50 days @@ -419,6 +419,8 @@ void WLED::setup() escapedMac.replace(":", ""); escapedMac.toLowerCase(); + // generate host name if no compile time default is set + if (strcmp(hostName, DEFAULT_MDNS_NAME) == 0) sprintf_P(hostName, PSTR("wled-%.*s"), 6, escapedMac.c_str() + 6); WLED_SET_AP_SSID(); // otherwise it is empty on first boot until config is saved multiWiFi.push_back(WiFiConfig(CLIENT_SSID,CLIENT_PASS)); // initialise vector with default WiFi @@ -486,8 +488,7 @@ void WLED::setup() WLED::instance().enableWatchdog(); #endif }); - if (strlen(cmDNS) > 0) - ArduinoOTA.setHostname(cmDNS); + ArduinoOTA.setHostname(hostName); } #endif #ifdef WLED_ENABLE_DMX @@ -652,22 +653,8 @@ void WLED::initConnection() if (WLED_WIFI_CONFIGURED) { showWelcomePage = false; - DEBUG_PRINTF_P(PSTR("Connecting to %s...\n"), multiWiFi[selectedWiFi].clientSSID); - - // convert the "serverDescription" into a valid DNS hostname (alphanumeric) - char hostname[25]; - prepareHostname(hostname); WiFi.begin(multiWiFi[selectedWiFi].clientSSID, multiWiFi[selectedWiFi].clientPass); // no harm if called multiple times - -#ifdef ARDUINO_ARCH_ESP32 - WiFi.setTxPower(wifi_power_t(txPower)); - WiFi.setSleep(!noWifiSleep); - WiFi.setHostname(hostname); -#else - wifi_set_sleep_type((noWifiSleep) ? NONE_SLEEP_T : MODEM_SLEEP_T); - WiFi.hostname(hostname); -#endif } #ifndef WLED_DISABLE_ESPNOW @@ -715,11 +702,11 @@ void WLED::initInterfaces() #endif // Set up mDNS responder: - if (strlen(cmDNS) > 0) { + if (mDNSenabled) { // "end" must be called before "begin" is called a 2nd time // see https://github.com/esp8266/Arduino/issues/7213 MDNS.end(); - MDNS.begin(cmDNS); + MDNS.begin(hostName); DEBUG_PRINTLN(F("mDNS started")); MDNS.addService("http", "tcp", 80); diff --git a/wled00/wled.h b/wled00/wled.h index 52bb2f936..d0c506858 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -336,7 +336,8 @@ WLED_GLOBAL char ntpServerName[33] _INIT("0.wled.pool.ntp.org"); // NTP server // WiFi CONFIG (all these can be changed via web UI, no need to set them here) WLED_GLOBAL std::vector multiWiFi; WLED_GLOBAL IPAddress dnsAddress _INIT_N((( 8, 8, 8, 8))); // Google's DNS -WLED_GLOBAL char cmDNS[33] _INIT(MDNS_NAME); // mDNS address (*.local, replaced by wledXXXXXX if default is used) +WLED_GLOBAL char hostName[33] _INIT(MDNS_NAME); // mDNS address (*.local, replaced by wled-XXXXXX if default is used) +WLED_GLOBAL bool mDNSenabled _INIT(true); // use mDNS (default is true, can be changed in web UI) WLED_GLOBAL char apSSID[33] _INIT(""); // AP off by default (unless setup) #ifdef WLED_SAVE_RAM typedef class WiFiOptions { diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 4434a2f3e..a80e7a0c2 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -232,7 +232,7 @@ static bool captivePortal(AsyncWebServerRequest *request) if (!request->hasHeader(F("Host"))) return false; String hostH = request->getHeader(F("Host"))->value(); - if (!isIp(hostH) && hostH.indexOf(F("wled.me")) < 0 && hostH.indexOf(cmDNS) < 0 && hostH.indexOf(':') < 0) { + if (!isIp(hostH) && hostH.indexOf(F("wled.me")) < 0 && hostH.indexOf(hostName) < 0 && hostH.indexOf(':') < 0) { DEBUG_PRINTLN(F("Captive portal")); AsyncWebServerResponse *response = request->beginResponse(302); response->addHeader(F("Location"), F("http://4.3.2.1")); diff --git a/wled00/xml.cpp b/wled00/xml.cpp index f821f86fb..bedecb731 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -172,6 +172,7 @@ void getSettingsJS(byte subPage, Print& settingsScript) if (subPage == SUBPAGE_WIFI) { size_t l; + char s[32]; settingsScript.printf_P(PSTR("resetWiFi(%d);"), WLED_MAX_WIFI_COUNT); for (size_t n = 0; n < multiWiFi.size(); n++) { l = strlen(multiWiFi[n].clientPass); @@ -194,7 +195,8 @@ void getSettingsJS(byte subPage, Print& settingsScript) printSetFormValue(settingsScript,PSTR("D2"),dnsAddress[2]); printSetFormValue(settingsScript,PSTR("D3"),dnsAddress[3]); - printSetFormValue(settingsScript,PSTR("CM"),cmDNS); + printSetFormValue(settingsScript,PSTR("CM"),hostName); + printSetFormCheckbox(settingsScript,PSTR("MD"),mDNSenabled); printSetFormIndex(settingsScript,PSTR("AB"),apBehavior); printSetFormValue(settingsScript,PSTR("AS"),apSSID); printSetFormCheckbox(settingsScript,PSTR("AH"),apHide); @@ -235,7 +237,6 @@ void getSettingsJS(byte subPage, Print& settingsScript) if (Network.isConnected()) //is connected { - char s[32]; IPAddress localIP = Network.localIP(); sprintf(s, "%d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]); @@ -248,14 +249,14 @@ void getSettingsJS(byte subPage, Print& settingsScript) printSetClassElementHTML(settingsScript,PSTR("sip"),0,(char*)F("Not connected")); } - if (WiFi.softAPIP()[0] != 0) //is active + if (apActive && WiFi.softAPIP()[0] != 0) //is active { - char s[16]; IPAddress apIP = WiFi.softAPIP(); - sprintf(s, "%d.%d.%d.%d", apIP[0], apIP[1], apIP[2], apIP[3]); + snprintf(s, sizeof(s)-1, "%d.%d.%d.%d", apIP[0], apIP[1], apIP[2], apIP[3]); printSetClassElementHTML(settingsScript,PSTR("sip"),1,s); } else { + // WiFi.softAPmacAddress() for AP MAC address printSetClassElementHTML(settingsScript,PSTR("sip"),1,(char*)F("Not active")); }