Wifimanager: Is it possible to reconfigure after autoconnect?

Created on 12 Dec 2016  Â·  47Comments  Â·  Source: tzapu/WiFiManager

This is such a great library. I cannot thank you enough for the time it has saved.

Can I ask how to force a reconfigure after using autoconnect? I read in your docs:

_Instead of calling autoConnect() which does all the connecting and failover configuration portal setup for you, you need to use startConfigPortal(). Do not use BOTH._

I would like to give users the opportunity to reconfigure some of the parameters (including the additional ones I have created), even if the unit has connected to wifi. I'd like to look for a continuous button press for a few seconds to trigger the config mode.

All 47 comments

In my view @smadds would be better off to use the IOT configurator for setting parameters other than WiFi configuration.

Here is an example of configuration on button press and here is an example where the button must be pushed for a few seconds to respond, and in this case you see a sliding bar on a screen. A button library is used that detects short press, long press, double press and, is button pressed now.

Thanks, Ken. I had a look at IOT Configurator and it looks interesting - albeit putting a dependency for a 3rd-party system. My main problem is not the button, but how to reconfigure the WiFi settings within WM. The best I've come up with so far is to use the WM reset function and then restart the device. This is not ideal, however, as it clears all of the settings - but works as a "restore to factory defaults" type of use case.

When @smadds says:

but how to reconfigure the WiFi settings within WM.

I don't understand but that's fine.

Theres an example called ondemand why not just do that or handle the button press how ever you want to start it. Whats the problem?

@smadds Did you ever figure out your button press to factory defaults? I am TOTALLY new to programming and have been beating my head against the wall for about a week trying to figure it out.

Any help you could give would be great!

Tnx
-J

guys, here s an example that includes logic for a button triggered reset of settings
https://github.com/tzapu/SonoffBoilerplate/blob/master/SonoffBoilerplate.ino

or

#define TRIGGER_PIN 0

void setup(){
  pinMode(TRIGGER_PIN, INPUT_PULLUP);
}

//crappy button handler for testing
//erase config reboot
void handleButton(){
  int debounce = 50;
  if ( digitalRead(TRIGGER_PIN) == LOW ){
    delay(debounce);
    if(digitalRead(TRIGGER_PIN) == LOW ){
      WiFiManager wifiManager;      
      wifiManager.resetSettings();
      delay(1000);
      ESP.reset();
    }
  }
}

void loop() {
  handleButton();
}

My request was to make the web page reset button more protected by adding a
confirm stage, which Theo has kindly done.

There is a button sequence for clearing locally stored settings - hold
button down for more than 4 seconds. See wiki/button page.

One issue I constantly have is a new install tries to connect to Theo's
mqtt server and this has a very long timeout, during which the system is
unresponsive. Beware if this!!

I usually try to get it into web manager mode first (4 button presses) ,
set the log on to its Wi-Fi access point, then configure the client Wi-Fi
ssid & password. I then look for it showing up on my Dhcp server, go to the
web page and update the mqtt before anything else. Lots of reboots, but
once you are at this stage it's plain sailing.

On 3 Jan 2017 01:19, "jaygrooms" notifications@github.com wrote:

@smadds https://github.com/smadds Did you ever figure out your button
press to factory defaults? I am TOTALLY new to programming and have been
beating my head against the wall for about a week trying to figure it out.

Any help you could give would be great!

Tnx
-J

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/tzapu/WiFiManager/issues/263#issuecomment-270039116,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFBCXmX9gT19AZMV23YZe5eMlpqyNBTdks5rOaIPgaJpZM4LLD-o
.

Interesting, Button hold and mutiple presses are easy to implement,there are many ways to do that.

I even wrote this to use a reset button to reset stuff.
https://gist.github.com/tablatronix/efa5d525d704e4b8b9ece31af0c99fdf

Hi I was wondering how to implement an wifiManager.autoConnect() on Setup and a wifiManager.startConfigPortal() when the button is pressed.
Both work very well separated but together ESP8266 crashes.
The problem with OnDemand example is that ESP8266 doesn't connect from scratch.
I need the device to get connected when it is plugged if the router is available and have the possibility to reconfigure with the button

Just add autoconnect and either 2 wm instances or move the class obj outside of setup

This exact thing is discussed in another issue i think

if WiFi.SSID() is an empty string then you could call autoConnect() and on button you call startConfigPortal()
so in all other cases WiFiManager would be not started.
on most of my sketches i just use autoConnect with setTimeout and a restart on said timeout. if router is unavailable in a few mins, it reboots and tries connecting again. works pretty well (for me)

Great I made it work, both with Master and Dev branch. The problem is that with Dev branch after WiFi configuration I cannot connect to a server client to send data or to update the clock using NTP server.
Same code runs ok with Master branch and connects to servers...

Can you elaborate, are you in sta mode or sta + ap mode,
Also what does the debug say ?

After doing ap mode and WiFi configuration.

Dev Branch. Problem trying to connect to servers
problem dev branch2

Master, connected to NTP and data servers. NTP pk and connected to server with a forbidden

problem solved master branch2

I checked and in Master, after pressing the button, startConfigPortal crashes after scan networks
In dev it works but never get connection to servers.

In conclusion, in dev branch, after configuration or after startConfigPortal, connection to servers doesn't work.
With WiFi configuration done, if you reboot, it works!

can you add an print mode after exit to see which mode you are in

or add WiFi.mode(WIFI_STA); after exiting portal, and see if it starts working ?

( that crash in master is new also, hmm )

which esp lib ver are you using ?

688

similar issue

investigating..

hmm I was trying to make a quick test sketch, but I cannot get this ntp example to work at all.
know a good ping lib ?

ah i forgot to start udp nm

cannot reproduce

*WM: [1] getCoreVersion():          2_4_1
*WM: [1] system_get_sdk_version():  2.2.1(cfd48f3)
*WM: [1] system_get_boot_version(): 31
*WM: [1] getFreeHeap():             42664

added some debugging to lib

also added ntp example to the dev/ example

cannot reproduce on staging either

I am using this library https://github.com/gmag11/NtpClient

It works adding WiFi.mode(WIFI_STA);!!! Thanks

What version of esp lib? There is clearly a bug

SDK Version 2.2.1
Core version 2.4.1
Boot version 4

Also in Dev branch setAPStaticIPConfig does not work! It always goes to 192.168.4.1

*WM: [1] SETTINGS ERASED
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [3] allocating params bytes: 20
*WM: [2] Added Parameter: server
*WM: [2] Added Parameter: port
*WM: [2] Added Parameter: TimeZone
*WM: [1] AutoConnect
*WM: [2] Connecting as wifi client...
*WM: [3] WIFI station disconnect
*WM: [1] No saved credentials, skipping wifi
*WM: [2] Connection result: WL_NO_SSID_AVAIL
*WM: [3] lastconxresult: WL_NO_SSID_AVAIL
*WM: [1] AutoConnect: FAILED
*WM: [2] AccessPoint set password is VALID
*WM: [1] xxxxxx
*WM: [3] WIFI station disconnect
*WM: [3] WiFi station enable
*WM: [2] Disabling STA
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: xxxxxx
*WM: [1] AP IP address: 192.168.4.1
Entered config mode
192.168.4.1

//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) {
Serial.println("Entered config mode");
myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
Serial.println(WiFi.softAPIP());
//if you used auto generated SSID, print it
Serial.println(myWiFiManager->getConfigPortalSSID());
//entered config mode, make led toggle faster
ticker.attach(0.2, tick);
}

thanks, callback was moved, fixed
5ee1ae78c0fc808ad5eacec398d19a658ec35aa3

I have added some debugging for this can you test and post debug log ?

*WM: [2] AccessPoint set password is VALID
*WM: [1] xxxxxx
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: xxxxxx
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [0] [ERROR] softAPConfig failed!
*WM: [1] AP IP address: 192.168.4.1
Entered config mode
192.168.4.1
xxxxxx
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan done in 1582ms
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] NUM CLIENTS: 0

Are you still using callback? Did you try setting it before wm starts?

Yes still using callback, is it better not to use it? Added settings but still going to 192.168.4.1

There is no need to use it, but curious where the bug is.

720

Updated development branch but still...
*WM: [2] AccessPoint set password is VALID
*WM: [1] XXXXX
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: XXXXX
Entered config mode
0.0.0.0
XXXXX
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [0] [ERROR] softAPConfig failed!
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] Portal Timeout In 118 seconds
*WM: [2] WiFi Scan ASYNC completed in 1589 ms
*WM: [2] WiFi Scan ASYNC found: 5
*WM: [2] Portal Timeout In 88 seconds

Doing a wifiManager.resetSettings();

mounted file system
reading config file
opened config file
{"mqtt_server":"xxxx","mqtt_port":"80","TimeZone":"-3","ip":"192.168.1.198","gateway":"192.168.1.254","subnet":"255.255.255.0"}
parsed json
xxxx
-3
*WM: [1] SETTINGS ERASED
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [3] allocating params bytes: 20
*WM: [2] Added Parameter: server
*WM: [2] Added Parameter: port
*WM: [2] Added Parameter: TimeZone
*WM: [1] AutoConnect
*WM: [2] Connecting as wifi client...
*WM: [3] WIFI station disconnect
*WM: [1] No saved credentials, skipping wifi
*WM: [2] Connection result: WL_NO_SSID_AVAIL
*WM: [3] lastconxresult: WL_NO_SSID_AVAIL
*WM: [1] AutoConnect: FAILED
*WM: [2] AccessPoint set password is VALID
*WM: [1] xxxx
*WM: [3] WIFI station disconnect
*WM: [3] WiFi station enable
*WM: [2] Disabling STA
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: xxxx
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [1] AP IP address: 10.0.1.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 10.0.1.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] WiFi Scan ASYNC completed in 2186 ms
*WM: [2] WiFi Scan ASYNC found: 9

And then pressing the button to start config portal
*WM: [2] AccessPoint set password is VALID
*WM: [1] xxxx
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: xxxx
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [0] [ERROR] softAPConfig failed!
*WM: [1] AP IP address: 10.0.1.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 10.0.1.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] Portal Timeout In 118 seconds
*WM: [2] WiFi Scan ASYNC completed in 1589 ms
*WM: [2] WiFi Scan ASYNC found: 8

Now it is working with 10.0.1.1 but when reset is deleted again it goes to 192.168.4.1

Ok well there is no callback if already connected so probably always set config first

Even adding setAPStaticIPConfig first

same output ?

Yes same output, even if I delete callback and add configuration first.
*WM: [2] AccessPoint set password is VALID
*WM: [1] xxxxx
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: xxxxx
Entered config mode
0.0.0.0
xxxxx
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [0] [ERROR] softAPConfig failed!
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] Portal Timeout In 118 seconds
*WM: [2] WiFi Scan ASYNC completed in 1586 ms
*WM: [2] WiFi Scan ASYNC found: 14

Ok sorry this is ap sta config , so different issue, ill try to debug today

@rodri16 can you create a new issue for this and fill out the info, I want to track this seperately this is getting confusing. You clearly have "softAPConfig failed" so this is either a sketch issue or a esp bug or wrong mode in wm before setting config.

Implementation using the double reset library:
https://github.com/guysoft/Mqtt_Wifi_manager

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liebman picture liebman  Â·  5Comments

tablatronix picture tablatronix  Â·  7Comments

VladoPortos picture VladoPortos  Â·  6Comments

bydoctor picture bydoctor  Â·  5Comments

gjt211 picture gjt211  Â·  7Comments