Skip to content

Commit

Permalink
fix for #782
Browse files Browse the repository at this point in the history
  • Loading branch information
tablatronix authored and tablatronix committed Jan 31, 2019
1 parent 9a4c0f1 commit 0865a36
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
WiFi.disconnect(); // this alone is not enough to stop the autoconnecter
WiFi.mode(WIFI_AP);
WiFi.persistent(true);
}
}
else {
//setup AP
WiFi.mode(WIFI_AP_STA);
Expand Down Expand Up @@ -232,33 +232,52 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
//HTTP
server->handleClient();


if (connect) {
delay(1000);
connect = false;
delay(2000);
DEBUG_WM(F("Connecting to new AP"));

// using user-provided _ssid, _pass in place of system-stored ssid and pass
if (connectWifi(_ssid, _pass) != WL_CONNECTED) {
DEBUG_WM(F("Failed to connect."));
} else {
//connected
WiFi.mode(WIFI_STA);
//notify that configuration has changed and any optional parameters should be saved
if ( _savecallback != NULL) {
//todo: check if any custom parameters actually exist, and check if they really changed maybe
_savecallback();

// if saving with no ssid filled in, reconnect to ssid
// will not exit cp
if(_ssid == ""){
DEBUG_WM(F("No ssid, skipping wifi"));
}
else{
DEBUG_WM(F("Connecting to new AP"));
if (connectWifi(_ssid, _pass) != WL_CONNECTED) {
delay(2000);
// using user-provided _ssid, _pass in place of system-stored ssid and pass
DEBUG_WM(F("Failed to connect."));
}
else {
//connected
WiFi.mode(WIFI_STA);
//notify that configuration has changed and any optional parameters should be saved
if ( _savecallback != NULL) {
//todo: check if any custom parameters actually exist, and check if they really changed maybe
_savecallback();
}
break;
}
break;
}

if (_shouldBreakAfterConfig) {
//flag set to exit after config after trying to connect
//notify that configuration has changed and any optional parameters should be saved
if ( _savecallback != NULL) {
//todo: check if any custom parameters actually exist, and check if they really changed maybe
_savecallback();
}
WiFi.mode(WIFI_STA); // turn off ap
// reconnect to ssid
// int res = WiFi.begin();
// attempt connect for 10 seconds
DEBUG_WM(F("Waiting for sta (10 secs) ......."));
for(size_t i = 0 ; i<100;i++){
if(WiFi.status() == WL_CONNECTED) break;
DEBUG_WM(".");
// Serial.println(WiFi.status());
delay(100);
}
delay(1000);
break;
}
}
Expand Down

0 comments on commit 0865a36

Please sign in to comment.