@@ -388,8 +388,8 @@ void wifiUpdate()
388
388
break ;
389
389
}
390
390
391
- // Process DNS when we are in AP mode for captive portal
392
- if (WiFi.getMode () == WIFI_AP && settings.enableCaptivePortal )
391
+ // Process DNS when we are in AP mode or AP+STA mode for captive portal
392
+ if ((( WiFi.getMode () == WIFI_AP) || (WiFi. getMode () == WIFI_AP_STA)) && settings.enableCaptivePortal )
393
393
{
394
394
dnsServer.processNextRequest ();
395
395
}
@@ -435,7 +435,7 @@ void wifiStop()
435
435
MDNS.end ();
436
436
437
437
// Stop the DNS server if we were using the captive portal
438
- if (WiFi.getMode () == WIFI_AP && settings.enableCaptivePortal )
438
+ if ((( WiFi.getMode () == WIFI_AP) || (WiFi. getMode () == WIFI_AP_STA)) && settings.enableCaptivePortal )
439
439
dnsServer.stop ();
440
440
441
441
// Stop the other network clients and then WiFi
@@ -486,16 +486,40 @@ bool wifiIsConnected()
486
486
// Attempts a connection to all provided SSIDs
487
487
// Returns true if successful
488
488
// Gives up if no SSID detected or connection times out
489
+ // If useAPSTAMode is true, do an extra check and go from WIFI_AP mode to WIFI_AP_STA mode
489
490
bool wifiConnect (unsigned long timeout)
491
+ {
492
+ return wifiConnect (timeout, false , nullptr );
493
+ }
494
+ bool wifiConnect (unsigned long timeout, bool useAPSTAMode, bool *wasInAPmode)
490
495
{
491
496
if (wifiIsConnected ())
492
497
return (true ); // Nothing to do
493
498
494
499
displayWiFiConnect ();
495
500
496
- // Before we can issue esp_wifi_() commands WiFi must be started
497
- if (WiFi.getMode () != WIFI_STA)
498
- WiFi.mode (WIFI_STA);
501
+ // If otaUpdate or otaCheckVersion wants to use WIFI_AP_STA mode
502
+ if (useAPSTAMode && (wasInAPmode != nullptr ))
503
+ {
504
+ *wasInAPmode = (WiFi.getMode () == WIFI_AP);
505
+
506
+ if (*wasInAPmode)
507
+ {
508
+ systemPrintln (" wifiConnect: changing from WIFI_AP to WIFI_AP_STA" );
509
+ WiFi.mode (WIFI_AP_STA); // Change mode from WIFI_AP to WIFI_AP_STA
510
+ }
511
+ else
512
+ {
513
+ systemPrintln (" wifiConnect: was not in WIFI_AP mode. Going to WIFI_STA" );
514
+ WiFi.mode (WIFI_STA); // Must have been off - or already in STA mode?
515
+ }
516
+ }
517
+ else
518
+ {
519
+ // Before we can issue esp_wifi_() commands WiFi must be started
520
+ if (WiFi.getMode () != WIFI_STA)
521
+ WiFi.mode (WIFI_STA);
522
+ }
499
523
500
524
// Verify that the necessary protocols are set
501
525
uint8_t protocols = 0 ;
0 commit comments