mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 09:05:56 +03:00
[GH-ISSUE #591] How to disconnect wifi and restart http server #494
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#494
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 @kotran88 on GitHub (Apr 13, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/591
----------------------------- Remove above -----------------------------
node mcu
and I'm using it with autoConnect("myWifi")
then connect wifi very well.
but I have disconnect button to disconnect.
if I press disconnect button,
wifiManager.resetSetting();
ESP.reset()
and Serial monitor says below.
*WM: settings invalidated
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
That's all!
I think It should restart http server to connect it right away.
but it stop wdt reset log.
I should build code again to connect wifi again.
How can I reset wifi and connect it again ?
-----------------------------------ADDED question --------------------
i changed code as below
wifiManager.resetSetting();
delay(500)
wifiManager.autoConnect("button");
and I upload code and connect button ssid successfully.
and "button" ssid has manage router property which lead to configuration portal to connect wifi.
http://i1.ruliweb.com/img/18/04/14/162c1c7b5ed3051.png
and after connected successfully, I disconnect .
Then, Serial Monitor says
*WM: settings invalidated
then come to autoconnect function as I expected.
but...problem is that It's not open configuration portal... but error
so, I checked button ssid wifi and found out that it dosen't have manage router ...
http://i1.ruliweb.com/img/18/04/14/162c1c7b01c3051.png
@tablatronix commented on GitHub (Apr 13, 2018):
Does it not autoconnect? Are you on usb and programming? You have to reset the module after programming for resets to work, its a esp known issue
@kotran88 commented on GitHub (Apr 14, 2018):
for wifiManager.resetSetting();
it 's not goes to auto connect automatically. but only shown *WM: settings invalidated.
reset the module mean ESP.reset()???
@tablatronix commented on GitHub (Apr 14, 2018):
If you are programming an esp over serial, you cannot soft reset until you hard reset. It is a limitation.
Hit reset after or repower it then try
@kotran88 commented on GitHub (Apr 14, 2018):
Thank you for answering !
you mean, hit reset. that mean , For node mcu , RST button on board?
after resetSetting() is done?
@kotran88 commented on GitHub (Apr 14, 2018):
I added question...can you check image and review it...? it's same reason? for soft reset, I should hard reset.
@tablatronix commented on GitHub (Apr 14, 2018):
YES, i see no image
Press reset after you program it, before you test
@n4rf commented on GitHub (Jun 4, 2019):
Sorry, Im quite late. But I have been sketching on a mesh of Wifi sensors that as far as it goes it works with no problems! Wifimanager did the trick quite flawlessly.
The only counterback I am having is that when ESP32 can not connect (usually becasue I am testing it for possible reasons it may not connect, such as password has changed), it enters on AP mode to configure it. So far so good.
When no Wifi settings (SSID/PASSWD) has been saved, it works flawlessly.
But, if there has been a previous (now not working) Wifi setting, when AP mode starts, and I connect to it, I have hard time to access the configuration page. Usually it hangs, or disconnects. Therefore I thought about making a "Reset configs" instance, to erase all previous settings.
If i manually erase the ESP32 flash, everything works well.
But, I dont want to have to manually erase each ESP32 everytime Wifi config changes.
Carefully reading the library, I came across this:
void WiFiManager::resetSettings() {
DEBUG_WM(F("settings invalidated"));
DEBUG_WM(
F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT "
"OUT AFTER ERASING THE DATA."));
// TODO On ESP32 this does not erase the SSID and password. See
// https://github.com/espressif/arduino-esp32/issues/400
// For now, use "make erase_flash".
WiFi.disconnect(true);
// delay(200);
}
Is there any chance this has had any progress? Or any suggestions as how I may aproach it?
Sorry for the issue, thanks in advance for the library and al the work done so far.
@n4rf commented on GitHub (Jun 6, 2019):
After reverse-engineering the ESP32 library I found a "quick-n-dirty" way to erase the saved WiFi Credentials that messed up with the access to the configuration portal.
Initially, WiFi.disconnect() does not work unless, your are connected, of course, but I needed a way to erase credentials because I am using Wifimanager and since I was not connected, and needed to save a new one, old credentials messed up the AP and STA mode, hence, I needed to erase previous saved credentials.
the trick is quite simple and it was in front of my eyes the whole time.
And that will erase the previously saved WiFi credentials and let me acccess to the configuration portal without problems
@tablatronix commented on GitHub (Jun 6, 2019):
What is wrong with wm.resetSettings()
Does it fail, is there a connect check in disconnect?
@n4rf commented on GitHub (Jun 6, 2019):
My setup to try if it worked (after my assumption it did not) was to setup a working SSID and Passphrase, and then wm.resetSettings(), it was supposed to erase the config, and therefore connection would have failed after restart. I kept reading on my serial monitor that connection status was "Connected" and pinging my server returned OK, so, config was not dropped.
On the library I am using, on WiFiManager.cpp on line 357 I found:
I read on other post that WiFi.disconnect() needs to be connected in order to work properly, which in my case, there is no guarantee SSID and passphrases would be permanent.
Like I said earlier, I needed to erase the config without a successful connection, reading the library it seems there is some sort of connect check before WiFi.disconnect cant do its job.
On WiFiSTA.cpp (esp32 WiFi library), on line 237 I found:
Of course, the eraseap is supposed to force the AP erase.. I tried WiFi.disconnect(false,true).. (true,true), (), etc.. same result every time... it kept connecting to my network after reset even after the instruction to erase the AP.
So, going to the basics, I found the esp_wifi_restore(), which needed esp_wifi_init() to allocate memory and the resources.
https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/network/esp_wifi.html
I found that WiFi.begin() uses this:
So after those instructions and a little delay it worked!
Final routine code to "restore to default WiFi settings"
during setup:
@tablatronix commented on GitHub (Jun 7, 2019):
No idea what library you are using.... its not this one..
Sounds like you are wasting your time, when you should be using our development branch
@phillezet commented on GitHub (Oct 28, 2020):
Sorry that this is of topic but I'm not sure how to contact with private message. @n4rf I'm trying to do what you have done, ESP32, WiFiManager and mesh (painlessmesh) but I'm not able to get it to work. Is it possible for you to share this part of your code? Like how you do the sequence in the start. Init -> WiFiManager -> mesh