mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 09:05:56 +03:00
[GH-ISSUE #1425] if wifi is initially not available, but becomes available, autoConnect() still fails, even if we try again #1221
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#1221
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 @DaleSchultz on GitHub (Jun 3, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1425
Basic Infos
Hardware
WiFimanager Branch/Release: 0.16.0
Esp8266
Hardware: Wemos D1 mini
Description
After a power failure, when power returns, my ESP devices boot up and attempt to join the network before the wifi router has started up. This means that after a power failure, all the ESP devices have to be restarted to get them on the network.
My expectation was that if the wifi network is absent, and the AP is started, that WifiManager would keep looking for the network, and connect to it if it appeared during the AP session. OK it does not do that, perhaps for technical reasons.
OK, so I thought what I will do is attempt a second call to autoConnect() if the first one times out. (I set the timeout to 180 seconds.)
To test the code I ran a wifi router that was powered off initially. During the first call to autoConnect() I powered the wifi router on. The network was thus present for the second call.
This also fails and the second call to autoConnect() prints a debug message that the credentials are not present. This is not true.
In case the credentials were being somehow 'hidden' by the first call, I ensured that the wifiManager object went out of scope and I created a second WifiManager object for the second call to autoConnect() so there could be no caching issues. Still does not work! (Code is below)
If I reset the ESP, leaving the router powered on WifiManager connected with the stored credentials on the first call.
It appears that WifiManager cannot connect to a wifi network that was not present when the ESP started.
I expect the second call after a 3 minute delay to work just like an initial call.
What can one do to make an ESP join the network if the network comes online after the ESP starts?
Settings in IDE
Module: Wemos D1
Code
Ouput
And here is the debug output from the serial monitor:
I then reset the ESP module and it connect the first try, proving that the credentials are in fact present.
@tablatronix commented on GitHub (Jun 17, 2022):
Seems unrelated, also not enough debugging or not using dev version
@jeroenst commented on GitHub (Sep 26, 2022):
Imo wifi manager should try to reconnect, even when the access point has started. When the connection succeeds the access point should be stopped.
@tablatronix commented on GitHub (Sep 26, 2022):
It is more complicated than that, leaving sta on when ap is on causes issues since they share channels. I have considered adding background ap scanning and if stored ssid shows up reconnect.
@jeroenst commented on GitHub (Sep 27, 2022):
Good point. Scanning is a very good idea. But prevent retrying to fast because when the key of the ap has changed it would be impossible to connect to the esp in ap mode. Also maybe pausebor slow down retrying when a client is connected.
@DaleSchultz commented on GitHub (Sep 29, 2022):
That would be great. Since it is very common for the wifi stack to take longer than an ESP, a background scan makes sense, and if the stored SSID appears, do a single attempt to connect. I think it would be fine to terminate the AP mode if the stored SSID appears, and go back to AP mode if the single connection attempt fails.
@tablatronix commented on GitHub (Sep 29, 2022):
I usually do this on my devices in user code, I do not automatically start captive portal everytime
@DaleSchultz commented on GitHub (Sep 29, 2022):
well yes, can you show working code that does that? My finding was that it appears that WifiManager cannot connect to a wifi network that was not present when the ESP started. (Even when attempted again 'manually' in code - see code in original post)
It is as if the WiFiManager caches the list of SSIDs and does not refresh that list.
@tablatronix commented on GitHub (Sep 30, 2022):
Nope you can turn off enableConfigPortal and use autoconnect over and over.
@DaleSchultz commented on GitHub (Sep 30, 2022):
For those who say this all works, remember the debug statements include:
Which is a clearly incorrect, since a reset allows the device to connect with the credentials it claimed were absent.
I am not sure if folk are ensuring that the SSID saved in the credentials is absent when WiFiManager is initially started.
Remember too, the SSID stored in the credentials is unknown to the code, and so it cannot be hard coded.
@tablatronix commented on GitHub (Oct 1, 2022):
This is an esp32 bug has since been fixed
@DaleSchultz commented on GitHub (Oct 1, 2022):
I am using ESP8266, are you saying there was a WiFiManager bug on ESP32 or the bad message was due to a bug on ESP32?
@tablatronix commented on GitHub (Oct 4, 2022):
oh hmm then nevermind.. hmm sounds like maybe creds are not actually saving or flash is corrupt.
I have not tested esp8266 in some time though
@rogerio-azevedo commented on GitHub (Mar 1, 2023):
I have this same problem reported. At first I thought there was a problem with my code, because the ESP sometimes reconnected, and sometimes it didn't.
What I noticed, and was able to reproduce on the bench, is that if the Internet does not come back when the ESP is running the setup, it thinks that the internet does not exist, it generates an AP and is in an infinite loop waiting for connections on the AP. After a simple reset on ESP, everything is back to normal operation!
Has anyone managed to resolve this issue?
@DaleSchultz commented on GitHub (Mar 1, 2023):
Since our code cannot access the WiFi manager stored credentials (which the debug code says does not exist) manual attempts to connect to the managed credentials are impossible.
I am only able to retry my default (hardcoded) creds in a loop if I find a matching SSID. As far as I can see there is no solution for WifiManager stored credentials, until this gets fixed. It means if WifiManager stored the wifi credentials, the ESP will not get onto the network after a power failure.
To reproduce:
Net result: can't expect an ESP using wifi manager to reconnect right away after a power failure without manual intervention (reset or power cycle or enter creds again?).
Unappealing solution:
@rogerio-azevedo commented on GitHub (Mar 1, 2023):
Thank you @DaleSchultz! Very good point here! Your solution seems to be something will work most of time. There is any lib to deal with wifi without set the name and credential on code?
I thought of a solution, if I could create it in the AP's loot, that if no one connects to the AP, the module resets, for example after 5 minutes. Would it be possible?
@DaleSchultz commented on GitHub (Mar 1, 2023):
I am not sure what other libraries exists for managing the gathering of wifi credentials.
I don't now what you mean by 'loot' but yes, if the AP could have a timeout and do a reset if nobody connects after the timeout, that would be a reasonable fix for the problem. Scanning periodically for the saved SSID, and using it when it appears, would be better though.
@rogerio-azevedo commented on GitHub (Mar 2, 2023):
I meant loop. I think I "solved" my problem by following your advice. I set a timeout time: wifiManager.setConfigPortalTimeout(120); Something surprising happened, after the timeout the board simulated a connection to a network that doesn't exist. And since I have a deal with the connection with the MQTT, if it doesn't connect I reset the board. So I think I solved my problem.
@rogerio-azevedo commented on GitHub (Mar 2, 2023):
@tablatronix commented on GitHub (Mar 3, 2023):
Yeah that is also a new esp bug it does eventually timeout for me, but by loop do you mean this #1563 or just the normal softap with no timeout set
you can maybe also set a connectTimeout to avoid using waitforconnectresult()