Skip to content

Commit b05f18d

Browse files
vortigontpre-commit-ci-lite[bot]
andauthoredSep 25, 2024··
fix: DNSServer Lib - improper startup code in WiFi mode (espressif#10366)
* DNSServer: fix improper startup code in WiFi mode When running on WiFi-AP mode server's start() method returned true while in fact UDP listening socket was never created Regression introduced in espressif#8760 Closes espressif#10330 * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 55bd1d5 commit b05f18d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ void setup() {
3939

4040
// by default DNSServer is started serving any "*" domain name. It will reply
4141
// AccessPoint's IP to all DNS request (this is required for Captive Portal detection)
42-
dnsServer.start();
42+
if (dnsServer.start()) {
43+
Serial.println("Started DNS server in captive portal-mode");
44+
} else {
45+
Serial.println("Err: Can't start DNS server!");
46+
}
4347

4448
// serve a simple root page
4549
server.on("/", handleRoot);

‎libraries/DNSServer/src/DNSServer.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ bool DNSServer::start() {
2222
#if SOC_WIFI_SUPPORTED
2323
if (WiFi.getMode() & WIFI_AP) {
2424
_resolvedIP = WiFi.softAPIP();
25-
return true;
25+
} else {
26+
return false; // won't run if WiFi is not in AP mode, or no WiFi
2627
}
28+
#else
29+
return false; // for other non WiFi-AP networking an overloaded method must be used to get device's IP
30+
// start(uint16_t port, const String &domainName, const IPAddress &resolvedIP)
2731
#endif
28-
return false; // won't run if WiFi is not in AP mode
2932
}
3033

3134
_udp.close();

0 commit comments

Comments
 (0)
Please sign in to comment.