Skip to content

Commit

Permalink
Merge branch 'hotfixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
tablatronix authored and tablatronix committed Jan 22, 2020
2 parents 368ea92 + 0865a36 commit f3c1964
Showing 1 changed file with 51 additions and 20 deletions.
71 changes: 51 additions & 20 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 Expand Up @@ -286,18 +305,30 @@ int WiFiManager::connectWifi(String ssid, String pass) {
DEBUG_WM(F("Already connected. Bailing out."));
return WL_CONNECTED;
}

DEBUG_WM(F("Status:"));
DEBUG_WM(WiFi.status());

wl_status_t res;
//check if we have ssid and pass and force those, if not, try with last saved values
if (ssid != "") {
WiFi.begin(ssid.c_str(), pass.c_str());
//trying to fix connection in progress hanging
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();
res = WiFi.begin(ssid.c_str(), pass.c_str(),0,NULL,true);
if(res != WL_CONNECTED){
DEBUG_WM(F("[ERROR] WiFi.begin res:"));
DEBUG_WM(res);
}
} else {
if (WiFi.SSID() != "") {
DEBUG_WM(F("Using last saved values, should be faster"));
//trying to fix connection in progress hanging
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();

WiFi.begin();
res = WiFi.begin();
} else {
DEBUG_WM(F("No saved credentials"));
}
Expand Down

0 comments on commit f3c1964

Please sign in to comment.