Skip to content

Commit f5b599e

Browse files
committed
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
1 parent 7018cd1 commit f5b599e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ 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!");
4346

4447
// serve a simple root page
4548
server.on("/", handleRoot);

libraries/DNSServer/src/DNSServer.cpp

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

3133
_udp.close();

0 commit comments

Comments
 (0)