Skip to content

Commit a57c9be

Browse files
committed
Move DNS to AP only mode.
1 parent e10ba00 commit a57c9be

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

Firmware/RTK_Surveyor/WiFi.ino

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ int wifiConnectionAttempts; // Count the number of connection attempts between r
4141
// Constants
4242
//----------------------------------------
4343

44-
4544
//----------------------------------------
4645
// Locals
4746
//----------------------------------------
@@ -60,10 +59,9 @@ static unsigned long wifiDisplayTimer;
6059
// Last time the WiFi state was displayed
6160
static uint32_t lastWifiState;
6261

63-
//DNS server for Captive Portal
62+
// DNS server for Captive Portal
6463
static DNSServer dnsServer;
6564

66-
6765
//----------------------------------------
6866
// WiFi Routines
6967
//----------------------------------------
@@ -180,8 +178,7 @@ byte wifiGetStatus()
180178
// Update the state of the WiFi state machine
181179
void wifiSetState(byte newState)
182180
{
183-
if ((settings.debugWifiState || PERIODIC_DISPLAY(PD_WIFI_STATE))
184-
&& (wifiState == newState))
181+
if ((settings.debugWifiState || PERIODIC_DISPLAY(PD_WIFI_STATE)) && (wifiState == newState))
185182
systemPrint("*");
186183
wifiState = newState;
187184

@@ -246,12 +243,17 @@ bool wifiStartAP()
246243
}
247244
systemPrint("WiFi AP Started with IP: ");
248245
systemPrintln(WiFi.softAPIP());
249-
246+
250247
// Start DNS Server
251-
if(dnsServer.start(53, "*", WiFi.softAPIP()) == false){
248+
if (dnsServer.start(53, "*", WiFi.softAPIP()) == false)
249+
{
252250
systemPrintln("WiFi DNS Server failed to start");
253251
return (false);
254-
};
252+
}
253+
else
254+
{
255+
log_d("DNS Server started");
256+
}
255257
}
256258
else
257259
{
@@ -363,11 +365,15 @@ void wifiUpdate()
363365
// If WiFi is connected, and no services require WiFi, shut it off
364366
else if (wifiIsNeeded() == false)
365367
wifiStop();
368+
366369
break;
367370
}
368-
//Process the next DNS request
369-
dnsServer.processNextRequest();
370371

372+
// Process DNS when we are in AP mode for captive portal
373+
if (WiFi.getMode() == WIFI_AP)
374+
{
375+
dnsServer.processNextRequest();
376+
}
371377
}
372378

373379
// Starts the WiFi connection state machine (moves from WIFI_OFF to WIFI_CONNECTING)
@@ -408,9 +414,10 @@ void wifiStop()
408414
if (settings.mdnsEnable == true)
409415
MDNS.end();
410416

411-
//Stop the DNS server
412-
dnsServer.stop();
413-
417+
// Stop the DNS server if we were using the captive portal
418+
if (WiFi.getMode() == WIFI_AP)
419+
dnsServer.stop();
420+
414421
// Stop the other network clients and then WiFi
415422
networkStop(NETWORK_TYPE_WIFI);
416423
}

0 commit comments

Comments
 (0)