Skip to content

Commit

Permalink
Use setBreakAfterConfig(true) from WiFiManager to ensure that save …
Browse files Browse the repository at this point in the history
…settings callback is called even when connection is unsuccessful (or user is just change settings).
  • Loading branch information
sidoh committed Nov 25, 2023
1 parent a6869e6 commit ead1d87
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ void wifiExtraSettingsChange() {
settings.wifiStaticIPGateway = wifiStaticIPGateway->getValue();
settings.wifiMode = Settings::wifiModeFromString(wifiMode->getValue());
settings.save();

// Restart the device
delay(1000);
ESP.restart();
}

// Called when a group is deleted via the REST API. Will publish an empty message to
Expand Down Expand Up @@ -383,7 +387,12 @@ void setup() {

// Allows us to have static IP config in the captive portal. Yucky pointers to pointers, just to have the settings carry through
wifiManager = new WiFiManager();

// Setting breakAfterConfig to true causes wifiExtraSettingsChange to be called whenever config params are changed
// (even when connection fails or user is just changing settings and not network)
wifiManager->setBreakAfterConfig(true);
wifiManager->setSaveConfigCallback(wifiExtraSettingsChange);

wifiManager->setConfigPortalBlocking(false);
wifiManager->setConnectTimeout(20);
wifiManager->setConnectRetries(5);
Expand Down

0 comments on commit ead1d87

Please sign in to comment.