mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 09:05:56 +03:00
[GH-ISSUE #87] Keep trying to connect #62
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#62
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @x10iman on GitHub (Jan 30, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/87
Thank you for this great lib which is very useful.My issue is that If for any reason there is power failure and both router and ESP goes down then if the ESP powers on before the router it enters the configuration mode and must be connected manually through the portal.
I have modified the WiFiManager.cpp along with OnDemandConfigPortal example to avoid such scenario.
Then ESP will enter a loop trying to connect to router until it gets connected. Then i moved the trigger pin function from the main loop to Setup function to call the portal in case the router WiFi credentials have been changed and then we can connect with new credentials or new network by holding trigger pin during boot time (factory default mode).
Please support if there is a better coding for my modifications.
Thanks again
WiFiManager.cpp :
`boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
DEBUG_WM(F(""));
DEBUG_WM(F("AutoConnect"));
// read eeprom for ssid and pass
String ssid = getSSID();
String pass = getPassword();
// attempt to connect; should it fail, fall back to AP
WiFi.mode(WIFI_STA);
if (connectWifi(ssid, pass) == WL_CONNECTED) {
DEBUG_WM(F("IP Address:"));
DEBUG_WM(WiFi.localIP());
//connected
return true;
}
//return startConfigPortal(apName, apPassword);
`
WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
.
.
.
// using user-provided _ssid, _pass in place of system-stored ssid amd pass
if (connectWifi(_ssid, _pass) != WL_CONNECTED) {
DEBUG_WM(F("Failed to connect."));
`
OnDemandConfigPortal.ino :
`
define TRIGGER_PIN 4 // cant be GPIO 0 nor 2
void setup() {
Serial.begin(115200);
pinMode(TRIGGER_PIN, INPUT);
WiFiManager wifiManager;
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW ) {
if (!wifiManager.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}
}
wifiManager.autoConnect("AutoConnectAP");// When power up try to connect using saved //credinital
Serial.println("connected...yeey :)");
}`
@tzapu commented on GitHub (Jan 31, 2016):
hi, you can already do this by just calling WiFi.begin() in loop in your sketch, on top of the OnDemandPortal example, with none of these modifications...
@x10iman commented on GitHub (Feb 1, 2016):
i tried that but but when i connect to router it failed and this what i got from serial monitor:
Starting
Exception (29):
epc1=0x402138f7 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000019 depc=0x00000000
ctx: cont
sp: 3fff0140 end: 3fff04f0 offset: 01a0
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
@tzapu commented on GitHub (Feb 4, 2016):
btw, you could also use an auto connect, and setTimeout
i use this on my battery powered devices, if they come up when router is down, they wait 2 mins, if no connection, they go back to sleep, they could reset and try again in your case. they would never get stuck this way
cheers
@tzapu commented on GitHub (Feb 4, 2016):
closed as retry ability is mentioned here
https://github.com/tzapu/WiFiManager/issues/87
@x10iman commented on GitHub (Feb 4, 2016):
Yes this way is very useful for saving power. But when the router is up again do I have to reset the ESP or it wil wake up automatically?
Sorry I am not that good in programming!
@tzapu commented on GitHub (Feb 5, 2016):
when the timeout occurs, wifi manager will return with false and you can do an ESP.reset(). this will restart the esp and retry connecting. instead of reset you can send it to sleep for an arbitrary period, and when it wakes up it tries again.