@@ -691,6 +691,63 @@ bool wifiStart()
691
691
return (wifiStatus == WL_CONNECTED);
692
692
}
693
693
694
+ // *********************************************************************
695
+ // Stop WiFi and release all resources
696
+ void wifiStop ()
697
+ {
698
+ // Stop the web server
699
+ stopWebServer ();
700
+
701
+ // Stop the DNS server if we were using the captive portal
702
+ if (((WiFi.getMode () == WIFI_AP) || (WiFi.getMode () == WIFI_AP_STA)) && settings.enableCaptivePortal )
703
+ dnsServer.stop ();
704
+
705
+ wifiFailedConnectionAttempts = 0 ; // Reset the counter
706
+
707
+ // If ESP-Now is active, change protocol to only Long Range
708
+ if (espnowGetState () > ESPNOW_OFF)
709
+ {
710
+ if (WiFi.getMode () != WIFI_STA)
711
+ WiFi.mode (WIFI_STA);
712
+
713
+ // Enable long range, PHY rate of ESP32 will be 512Kbps or 256Kbps
714
+ // esp_wifi_set_protocol requires WiFi to be started
715
+ esp_err_t response = esp_wifi_set_protocol (WIFI_IF_STA, WIFI_PROTOCOL_LR);
716
+ if (response != ESP_OK)
717
+ systemPrintf (" wifiShutdown: Error setting ESP-Now lone protocol: %s\r\n " , esp_err_to_name (response));
718
+ else
719
+ {
720
+ if (settings.debugWifiState == true )
721
+ systemPrintln (" WiFi disabled, ESP-Now left in place" );
722
+ }
723
+ }
724
+ else
725
+ {
726
+ WiFi.mode (WIFI_OFF);
727
+ if (settings.debugWifiState == true )
728
+ systemPrintln (" WiFi Stopped" );
729
+ }
730
+
731
+ // Take the network offline
732
+ networkInterfaceInternetConnectionLost (NETWORK_WIFI);
733
+
734
+ if (wifiMulti != nullptr )
735
+ wifiMulti = nullptr ;
736
+
737
+ // Display the heap state
738
+ reportHeapNow (settings.debugWifiState );
739
+ wifiStationRunning = false ;
740
+ wifiApRunning = false ;
741
+ }
742
+
743
+ // *********************************************************************
744
+ // Needed for wifiStopSequence
745
+ void wifiStop (NetIndex_t index, uintptr_t parameter, bool debug)
746
+ {
747
+ wifiStop ();
748
+ networkSequenceNextEntry (NETWORK_WIFI, settings.debugNetworkLayer );
749
+ }
750
+
694
751
// *********************************************************************
695
752
// Constructor
696
753
// Inputs:
@@ -3200,63 +3257,6 @@ NETWORK_POLL_SEQUENCE wifiStopSequence[] = {
3200
3257
{nullptr , 0 , " Termination" },
3201
3258
};
3202
3259
3203
- // ----------------------------------------
3204
- // Stop WiFi and release all resources
3205
- // ----------------------------------------
3206
- void wifiStop ()
3207
- {
3208
- // Stop the web server
3209
- stopWebServer ();
3210
-
3211
- // Stop the DNS server if we were using the captive portal
3212
- if (((WiFi.getMode () == WIFI_AP) || (WiFi.getMode () == WIFI_AP_STA)) && settings.enableCaptivePortal )
3213
- dnsServer.stop ();
3214
-
3215
- wifiFailedConnectionAttempts = 0 ; // Reset the counter
3216
-
3217
- // If ESP-Now is active, change protocol to only Long Range
3218
- if (espnowGetState () > ESPNOW_OFF)
3219
- {
3220
- if (WiFi.getMode () != WIFI_STA)
3221
- WiFi.mode (WIFI_STA);
3222
-
3223
- // Enable long range, PHY rate of ESP32 will be 512Kbps or 256Kbps
3224
- // esp_wifi_set_protocol requires WiFi to be started
3225
- esp_err_t response = esp_wifi_set_protocol (WIFI_IF_STA, WIFI_PROTOCOL_LR);
3226
- if (response != ESP_OK)
3227
- systemPrintf (" wifiShutdown: Error setting ESP-Now lone protocol: %s\r\n " , esp_err_to_name (response));
3228
- else
3229
- {
3230
- if (settings.debugWifiState == true )
3231
- systemPrintln (" WiFi disabled, ESP-Now left in place" );
3232
- }
3233
- }
3234
- else
3235
- {
3236
- WiFi.mode (WIFI_OFF);
3237
- if (settings.debugWifiState == true )
3238
- systemPrintln (" WiFi Stopped" );
3239
- }
3240
-
3241
- // Take the network offline
3242
- networkInterfaceInternetConnectionLost (NETWORK_WIFI);
3243
-
3244
- if (wifiMulti != nullptr )
3245
- wifiMulti = nullptr ;
3246
-
3247
- // Display the heap state
3248
- reportHeapNow (settings.debugWifiState );
3249
- wifiStationRunning = false ;
3250
- wifiApRunning = false ;
3251
- }
3252
-
3253
- // Needed for wifiStopSequence
3254
- void wifiStop (NetIndex_t index, uintptr_t parameter, bool debug)
3255
- {
3256
- wifiStop ();
3257
- networkSequenceNextEntry (NETWORK_WIFI, settings.debugNetworkLayer );
3258
- }
3259
-
3260
3260
// Returns true if we deem WiFi is not going to connect
3261
3261
// Used to allow cellular to start
3262
3262
bool wifiUnavailable ()
0 commit comments