[GH-ISSUE #1459] WiFiManager::waitForConnectResult > while(millis() < timeoutmillis) #1249

Open
opened 2026-02-28 01:29:14 +03:00 by kerem · 2 comments
Owner

Originally created by @Ramim256 on GitHub (Jul 24, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1459

I want to execute some line of code from my sketch when it's trying to connect, I mean when it is in the while loop printing the ".", at "WiFiManager.cpp > WiFiManager::waitForConnectResult > while(millis() < timeoutmillis)";
is there any possible way to do this ??

Originally created by @Ramim256 on GitHub (Jul 24, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1459 I want to execute some line of code from my sketch when it's trying to connect, I mean when it is in the while loop printing the ".", at "WiFiManager.cpp > WiFiManager::waitForConnectResult > while(millis() < timeoutmillis)"; is there any possible way to do this ??
Author
Owner

@tablatronix commented on GitHub (Jul 24, 2022):

I can add a callback here and see if it helps, you have to be careful though as wifi is very busy during this time and you can cause crashes, certainly no interrupts for eg.

another option I am considering
#1460

Another workaround is using your own esp event function and check for events that the esp lib emits when connecting.

If you have more info on your scenario, I can offer specific suggestions here

<!-- gh-comment-id:1193326101 --> @tablatronix commented on GitHub (Jul 24, 2022): I can add a callback here and see if it helps, you have to be careful though as wifi is very busy during this time and you can cause crashes, certainly no interrupts for eg. another option I am considering #1460 Another workaround is using your own esp event function and check for events that the esp lib emits when connecting. If you have more info on your scenario, I can offer specific suggestions here
Author
Owner

@Ramim256 commented on GitHub (Jul 28, 2022):

i want to access "ssid" variable from the main sketch, and execute some line of code from my sketch when it's trying to connect,
my code for 0.91 inch OLED display,
image

demo code:
void connectWiFi(void)
{
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
display.clearDisplay();
WiFi.begin(ssid, password);
int i = 10;
int j = 0;
if (WiFi.status() != WL_CONNECTED) {
while (currentMillis - previousMillis > reconnectInterval * 1000)
{
delay(500);
Serial.print(currentMillis - previousMillis);
Serial.print("\n");
if (i < 120) {
robojaxText("Connecting to ", 28, 0, 1, false);
robojaxText(ssid, 13, 14, 1, false);
robojaxText(".\n", i, 22, 1, false);
i = i + 5;
display.display();
if (WiFi.status() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
String ipa = WiFi.localIP().toString();
display.clearDisplay();
robojaxText("Connected: ", 32, 0, 1, true);
robojaxText(ipa, 20, 12, 1, true);
delay(5000);
return;
}
}
else {
i = 10;
display.clearDisplay();
j = j + 1;
}
if (j > 1) {
display.clearDisplay();
reconnectInterval = 50;
robojaxText("Failed to Connect ", 12, 8, 1, false);
robojaxText("Retring in ", 6, 23, 1, false);
robojaxText(String(reconnectInterval), 72, 23, 1, false);
robojaxText("second", 92, 23, 1, false); //second
display.display();
delay(5000);
previousMillis = currentMillis;
j = 0;
}
}
}
}

<!-- gh-comment-id:1197955869 --> @Ramim256 commented on GitHub (Jul 28, 2022): i want to access "ssid" variable from the main sketch, and execute some line of code from my sketch when it's trying to connect, my code for 0.91 inch OLED display, ![image](https://user-images.githubusercontent.com/20925210/181484396-95cd2670-8586-482b-ae2a-40b439abf725.png) demo code: void connectWiFi(void) { Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); display.clearDisplay(); WiFi.begin(ssid, password); int i = 10; int j = 0; if (WiFi.status() != WL_CONNECTED) { while (currentMillis - previousMillis > reconnectInterval * 1000) { delay(500); Serial.print(currentMillis - previousMillis); Serial.print("\n"); if (i < 120) { robojaxText("Connecting to ", 28, 0, 1, false); robojaxText(ssid, 13, 14, 1, false); robojaxText(".\n", i, 22, 1, false); i = i + 5; display.display(); if (WiFi.status() == WL_CONNECTED) { Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); String ipa = WiFi.localIP().toString(); display.clearDisplay(); robojaxText("Connected: ", 32, 0, 1, true); robojaxText(ipa, 20, 12, 1, true); delay(5000); return; } } else { i = 10; display.clearDisplay(); j = j + 1; } if (j > 1) { display.clearDisplay(); reconnectInterval = 50; robojaxText("Failed to Connect ", 12, 8, 1, false); robojaxText("Retring in ", 6, 23, 1, false); robojaxText(String(reconnectInterval), 72, 23, 1, false); robojaxText("second", 92, 23, 1, false); //second display.display(); delay(5000); previousMillis = currentMillis; j = 0; } } } }
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1249
No description provided.