Skip to content

Commit fe0853a

Browse files
committed
Don't MDNS.end() unless it was started
1 parent d3bf6a6 commit fe0853a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
//----------------------------------------
3535

3636
int wifiConnectionAttempts; // Count the number of connection attempts between restarts
37+
bool mdnsIsRunning = false; // Ending mdns when it was not yet started causes it to fail to start
3738

3839
#ifdef COMPILE_WIFI
3940

@@ -255,7 +256,6 @@ bool wifiStartAP(bool forceAP)
255256
WiFi.softAPConfig(local_IP, gateway, subnet);
256257

257258
const char *softApSsid = "RTK Config";
258-
259259
if (WiFi.softAP(softApSsid) == false) // Must be short enough to fit OLED Width
260260
{
261261
systemPrintln("WiFi AP failed to start");
@@ -432,8 +432,11 @@ void wifiStop()
432432
stopWebServer();
433433

434434
// Stop the multicast domain name server
435-
if (settings.mdnsEnable == true)
435+
if (mdnsIsRunning == true && settings.mdnsEnable == true)
436+
{
436437
MDNS.end();
438+
mdnsIsRunning = false;
439+
}
437440

438441
// Stop the DNS server if we were using the captive portal
439442
if (WiFi.getMode() == WIFI_AP && settings.enableCaptivePortal)
@@ -551,7 +554,10 @@ bool wifiConnect(unsigned long timeout)
551554
if (MDNS.begin("rtk") == false) // This should make the device findable from 'rtk.local' in a browser
552555
systemPrintln("Error setting up MDNS responder!");
553556
else
557+
{
554558
MDNS.addService("http", "tcp", settings.httpPort); // Add service to MDNS
559+
mdnsIsRunning = true;
560+
}
555561
}
556562
}
557563

0 commit comments

Comments
 (0)