@@ -2213,29 +2213,33 @@ const char * RTK_WIFI::stationSsid()
2213
2213
// Returns true if the modes were successfully configured
2214
2214
bool RTK_WIFI::stopStart (WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2215
2215
{
2216
+ const WIFI_ACTION_t allOnline = WIFI_AP_ONLINE | WIFI_EN_ESP_NOW_ONLINE | WIFI_STA_ONLINE;
2216
2217
int authIndex;
2217
2218
WIFI_CHANNEL_t channel;
2218
2219
bool defaultChannel;
2219
2220
WIFI_ACTION_t delta;
2220
- bool enabled ;
2221
+ WIFI_ACTION_t expected ;
2221
2222
WIFI_ACTION_t mask;
2222
2223
WIFI_ACTION_t notStarted;
2223
2224
uint8_t primaryChannel;
2224
2225
WIFI_ACTION_t restarting;
2226
+ bool restartWiFiStation;
2225
2227
wifi_second_chan_t secondaryChannel;
2226
2228
WIFI_ACTION_t startingNow;
2227
2229
esp_err_t status;
2228
2230
WIFI_ACTION_t stillRunning;
2229
2231
2230
2232
// Determine the next actions
2231
2233
notStarted = 0 ;
2232
- enabled = true ;
2234
+ restartWiFiStation = false ;
2233
2235
2234
2236
// Display the parameters
2235
2237
if (settings.debugWifiState && _verbose)
2236
2238
{
2239
+ systemPrintf (" WiFi: RTK_WIFI::stopStart called\r\n " );
2237
2240
systemPrintf (" stopping: 0x%08x\r\n " , stopping);
2238
2241
systemPrintf (" starting: 0x%08x\r\n " , starting);
2242
+ reportHeapNow (true );
2239
2243
}
2240
2244
2241
2245
// ****************************************
@@ -2253,8 +2257,7 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2253
2257
// Determine if there is an active channel
2254
2258
defaultChannel = _usingDefaultChannel;
2255
2259
_usingDefaultChannel = false ;
2256
- if (((_started & ~stopping) & (WIFI_AP_ONLINE | WIFI_EN_ESP_NOW_ONLINE | WIFI_STA_ONLINE))
2257
- && wifiChannel && !defaultChannel)
2260
+ if ((allOnline & _started & ~stopping) && wifiChannel && !defaultChannel)
2258
2261
{
2259
2262
// Continue to use the active channel
2260
2263
channel = wifiChannel;
@@ -2329,14 +2332,18 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2329
2332
// Only stop the started components
2330
2333
stopping &= _started;
2331
2334
2335
+ // Determine the components that are being started
2336
+ expected = starting & allOnline;
2337
+
2332
2338
// Determine which components are being restarted
2333
2339
restarting = _started & stopping & starting;
2334
2340
if (settings.debugWifiState && _verbose)
2335
2341
{
2336
2342
systemPrintf (" 0x%08x: _started\r\n " , _started);
2337
2343
systemPrintf (" 0x%08x: stopping\r\n " , stopping);
2338
2344
systemPrintf (" 0x%08x: starting\r\n " , starting);
2339
- systemPrintf (" 0x%08x: restarting\r\n " , starting);
2345
+ systemPrintf (" 0x%08x: restarting\r\n " , restarting);
2346
+ systemPrintf (" 0x%08x: expected\r\n " , expected);
2340
2347
}
2341
2348
2342
2349
// Don't start components that are already running and are not being
@@ -2564,7 +2571,11 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2564
2571
2565
2572
// Stop use of SSID and password
2566
2573
if (stopping & WIFI_AP_SET_SSID_PASSWORD)
2574
+ {
2567
2575
_started = _started & ~WIFI_AP_SET_SSID_PASSWORD;
2576
+ if (_apSsid)
2577
+ _apSsid[0 ] = 0 ;
2578
+ }
2568
2579
2569
2580
stillRunning = _started;
2570
2581
@@ -2639,6 +2650,8 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2639
2650
systemPrintf (" channel: %d\r\n " , channel);
2640
2651
_started = _started | WIFI_STA_START_SCAN;
2641
2652
2653
+ displayWiFiConnect ();
2654
+
2642
2655
// Determine if WiFi scan failed, stop WiFi station startup
2643
2656
if (wifi.stationScanForAPs (channel) < 0 )
2644
2657
{
@@ -2655,9 +2668,11 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2655
2668
if (channel == 0 )
2656
2669
{
2657
2670
if (wifiChannel)
2658
- systemPrintf (" WiFi STA: No compatible remote AP found on channel %d!\r\n " , wifiChannel);
2671
+ systemPrintf (" WiFi STA: No matching remote AP found on channel %d!\r\n " , wifiChannel);
2659
2672
else
2660
- systemPrintf (" WiFi STA: No compatible remote AP found!\r\n " );
2673
+ systemPrintf (" WiFi STA: No matching remote AP found!\r\n " );
2674
+
2675
+ displayNoWiFi (2000 );
2661
2676
2662
2677
// Stop bringing up WiFi station
2663
2678
starting &= ~WIFI_STA_NO_REMOTE_AP;
@@ -2693,7 +2708,15 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2693
2708
// Set the soft AP SSID and password
2694
2709
if (starting & WIFI_AP_SET_SSID_PASSWORD)
2695
2710
{
2696
- if (!softApSetSsidPassword (wifiSoftApSsid, wifiSoftApPassword))
2711
+ // Append the last four digits of the MAC address
2712
+ if (strlen (_apSsid) == 0 )
2713
+ {
2714
+ snprintf (_apSsid, SSID_LENGTH, " %s %02X%02X" , wifiSoftApSsid, btMACAddress[4 ], btMACAddress[5 ]);
2715
+ _apSsid[SSID_LENGTH - 1 ] = 0 ;
2716
+ }
2717
+
2718
+ // Set the soft AP SSID and password
2719
+ if (!softApSetSsidPassword (_apSsid, wifiSoftApPassword))
2697
2720
break ;
2698
2721
_started = _started | WIFI_AP_SET_SSID_PASSWORD;
2699
2722
}
@@ -2718,12 +2741,14 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2718
2741
// Set the soft AP host name
2719
2742
if (starting & WIFI_AP_SET_HOST_NAME)
2720
2743
{
2744
+ const char * hostName = &settings.mdnsHostName [0 ];
2745
+
2721
2746
// Display the host name
2722
2747
if (settings.debugWifiState && _verbose)
2723
- systemPrintf (" Host name: %s\r\n " , &settings. mdnsHostName [ 0 ] );
2748
+ systemPrintf (" Host name: %s\r\n " , hostName );
2724
2749
2725
2750
// Set the host name
2726
- if (!softApSetHostName (&settings. mdnsHostName [ 0 ] ))
2751
+ if (!softApSetHostName (hostName ))
2727
2752
break ;
2728
2753
_started = _started | WIFI_AP_SET_HOST_NAME;
2729
2754
}
@@ -2750,7 +2775,7 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2750
2775
2751
2776
// Display the soft AP status
2752
2777
systemPrintf (" WiFi: Soft AP online, SSID: %s (%s)%s%s\r\n " ,
2753
- wifiSoftApSsid ,
2778
+ _apSsid ? _apSsid : " " ,
2754
2779
_apIpAddress.toString ().c_str (),
2755
2780
wifiSoftApPassword ? " , Password: " : " " ,
2756
2781
wifiSoftApPassword ? wifiSoftApPassword : " " );
@@ -2760,15 +2785,19 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2760
2785
// Start the WiFi station components
2761
2786
// ****************************************
2762
2787
2788
+ restartWiFiStation = true ;
2789
+
2763
2790
// Set the host name
2764
2791
if (starting & WIFI_STA_SET_HOST_NAME)
2765
2792
{
2793
+ const char * hostName = &settings.mdnsHostName [0 ];
2794
+
2766
2795
// Display the host name
2767
2796
if (settings.debugWifiState && _verbose)
2768
- systemPrintf (" Host name: %s\r\n " , &settings. mdnsHostName [ 0 ] );
2797
+ systemPrintf (" Host name: %s\r\n " , hostName );
2769
2798
2770
2799
// Set the host name
2771
- if (!stationHostName (&settings. mdnsHostName [ 0 ] ))
2800
+ if (!stationHostName (hostName ))
2772
2801
break ;
2773
2802
_started = _started | WIFI_STA_SET_HOST_NAME;
2774
2803
}
@@ -2824,6 +2853,7 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2824
2853
// Mark the station online
2825
2854
if (starting & WIFI_STA_ONLINE)
2826
2855
{
2856
+ restartWiFiStation = false ;
2827
2857
_started = _started | WIFI_STA_ONLINE;
2828
2858
systemPrintf (" WiFi: Station online (%s: %s)\r\n " ,
2829
2859
_staRemoteApSsid, _staIpAddress.toString ().c_str ());
@@ -2931,9 +2961,6 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2931
2961
_staMacAddress[3 ], _staMacAddress[4 ], _staMacAddress[5 ],
2932
2962
wifiChannel);
2933
2963
}
2934
-
2935
- // All components started successfully
2936
- enabled = true ;
2937
2964
} while (0 );
2938
2965
2939
2966
// ****************************************
@@ -2979,9 +3006,24 @@ bool RTK_WIFI::stopStart(WIFI_ACTION_t stopping, WIFI_ACTION_t starting)
2979
3006
if (settings.debugWifiState && _verbose && _started)
2980
3007
displayComponents (" Started items" , _started);
2981
3008
3009
+ // Restart WiFi if necessary
3010
+ if (restartWiFiStation)
3011
+ wifiReconnectRequest = true ;
3012
+
3013
+ // Set the online flags
3014
+ wifiEspNowOnline = espNowOnline ();
3015
+ wifiSoftApOnline = softApOnline ();
3016
+ wifiStationOnline = stationOnline ();
3017
+
2982
3018
// Return the enable status
3019
+ bool enabled = ((_started & allOnline) == expected);
2983
3020
if (!enabled)
2984
- systemPrintf (" ERROR: RTK_WIFI::enable failed!\r\n " );
3021
+ systemPrintf (" ERROR: RTK_WIFI::stopStart failed!\r\n " );
3022
+ if (settings.debugWifiState && _verbose)
3023
+ {
3024
+ reportHeapNow (true );
3025
+ systemPrintf (" WiFi: RTK_WIFI::stopStart returning; %s\r\n " , enabled ? " true" : " false" );
3026
+ }
2985
3027
return enabled;
2986
3028
}
2987
3029
0 commit comments