@@ -341,11 +341,15 @@ bool wifiSoftApSsidSet; // Set when the WiFi soft AP SSID string exists
341
341
bool wifiStationRestart; // Restart Wifi station
342
342
bool wifiStationSsidSet; // Set when one or more SSID strings exist
343
343
344
+ static struct Settings *wifiPreviousSettings;
345
+
344
346
// *********************************************************************
345
347
// Set WiFi credentials
346
348
// Enable TCP connections
347
349
void menuWiFi ()
348
350
{
351
+ wifiSettingsClone (); // Create a copy of settings to detect if WiFi settings change
352
+
349
353
while (1 )
350
354
{
351
355
networkDisplayInterface (NETWORK_WIFI_STATION);
@@ -418,9 +422,26 @@ void menuWiFi()
418
422
clearBuffer (); // Empty buffer of any newline chars
419
423
}
420
424
425
+ // ----------------------------------------
426
+ // Check the settings and free the settings structure
427
+ // ----------------------------------------
428
+ bool wifiSettingsChangedAndFree ()
429
+ {
430
+ bool changed;
431
+
432
+ changed = false ;
433
+ if (wifiPreviousSettings)
434
+ {
435
+ changed = wifiSettingsChanged (wifiPreviousSettings);
436
+ rtkFree (wifiPreviousSettings, " WiFi previous settings" );
437
+ wifiPreviousSettings = nullptr ;
438
+ }
439
+ return changed;
440
+ }
441
+
421
442
// *********************************************************************
422
443
// Check for setting differences
423
- bool wifiCheckSettings (struct Settings *newSettings)
444
+ bool wifiSettingsChanged (struct Settings *newSettings)
424
445
{
425
446
bool changed;
426
447
@@ -434,14 +455,21 @@ bool wifiCheckSettings(struct Settings *newSettings)
434
455
(memcmp (newSettings->wifiNetworks [2 ].password , settings.wifiNetworks [2 ].password , PASSWORD_LENGTH) != 0 ) ||
435
456
(memcmp (newSettings->wifiNetworks [3 ].ssid , settings.wifiNetworks [3 ].ssid , SSID_LENGTH) != 0 ) ||
436
457
(memcmp (newSettings->wifiNetworks [3 ].password , settings.wifiNetworks [3 ].password , PASSWORD_LENGTH) != 0 );
437
- if (changed)
438
- {
439
- // Update the WiFi settings
440
- wifiUpdateSettings ();
441
- }
442
458
return changed;
443
459
}
444
460
461
+ // ----------------------------------------
462
+ // Allocate the settings structure and clone the settings
463
+ // ----------------------------------------
464
+ void wifiSettingsClone ()
465
+ {
466
+ wifiPreviousSettings = (struct Settings *)rtkMalloc (sizeof (settings), " WiFi previous settings" );
467
+ if (wifiPreviousSettings == nullptr )
468
+ systemPrintln (" ERROR: WiFi failed to allocate previous settings!\r\n " );
469
+ else
470
+ memcpy (wifiPreviousSettings, &settings, sizeof (settings));
471
+ }
472
+
445
473
// *********************************************************************
446
474
// Display the soft AP details
447
475
void wifiDisplayNetworkData ()
@@ -1070,9 +1098,21 @@ void wifiUpdateSettings()
1070
1098
// Remember the change in SSID values
1071
1099
wifiStationSsidSet = ssidSet;
1072
1100
1073
- // If there are consumers, and WiFi currently has connectivity, don't restart it
1074
- if ((networkConsumerCount (NETWORK_WIFI_STATION) > 0 ) && (networkHasInternet () == false ))
1101
+ // If there are consumers, and WiFi currently is not connected, then allow restart
1102
+ if ((networkConsumerCount (NETWORK_WIFI_STATION) > 0 ) &&
1103
+ (networkInterfaceHasInternet (NETWORK_WIFI_STATION) == false ))
1104
+ {
1105
+ if (settings.debugWifiState )
1106
+ systemPrintln (" Restarting WiFi because settings have changed" );
1107
+ wifiStationRestart = ssidSet;
1108
+ }
1109
+
1110
+ // If we are connected over WiFi, and settings change, restart connection
1111
+ bool wifiChanged =
1112
+ wifiSettingsChangedAndFree (); // Check to see if WiFi settings have been changed, then clear memory
1113
+ if (wifiChanged == true && networkInterfaceHasInternet (NETWORK_WIFI_STATION) == true )
1075
1114
{
1115
+ // Restart network
1076
1116
if (settings.debugWifiState )
1077
1117
systemPrintln (" Restarting WiFi because settings have changed" );
1078
1118
wifiStationRestart = ssidSet;
0 commit comments