Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example is starting configuration Portal twice #1371

Closed
ChristophCaina opened this issue Mar 10, 2022 · 20 comments
Closed

Example is starting configuration Portal twice #1371

ChristophCaina opened this issue Mar 10, 2022 · 20 comments
Labels
bug Validated BUG

Comments

@ChristophCaina
Copy link

ChristophCaina commented Mar 10, 2022

Hi, I am trying some of your examples provided here and it seems that I run into an issue...
Currently, the following Example Sketch was used: AutoConnectNonBlocking.ino

I am trying to create a configuration portal and a Wifi Network with a specific SSID...
When Running the sketch I can see, that this is working as expected in the Serial Monitor - but then, the code starts to repeate (before the Portal timeout has been reached) and then, it is using a different SSID than given in my code...

Here's the Output from the serial monitor

12:23:07.388 -> *wm:[1] SETTINGS ERASED 
12:23:07.388 -> *wm:[1] AutoConnect 
12:23:07.388 -> *wm:[1] No Credentials are Saved, skipping connect 
12:23:07.388 -> *wm:[2] Starting Config Portal 
12:23:07.388 -> *wm:[2] Disabling STA 
12:23:07.388 -> *wm:[2] Enabling AP 
12:23:07.388 -> *wm:[1] StartAP with SSID:  NCC1701D
12:23:07.899 -> *wm:[2] AP has anonymous access! 
12:23:08.385 -> *wm:[1] AP IP address: 192.168.4.1
12:23:08.385 -> *wm:[1] Starting Web Portal 
12:23:08.385 -> *wm:[2] HTTP server started 
12:23:08.385 -> *wm:[2] Config Portal Running, non blocking/processing 
12:23:08.421 -> *wm:[2] Portal Timeout In 60 seconds
12:23:08.421 -> Configportal running
12:23:08.421 -> *wm:[2] Starting Config Portal 
12:23:08.421 -> *wm:[2] Disabling STA 
12:23:08.421 -> *wm:[2] Enabling AP 
12:23:08.421 -> *wm:[1] StartAP with SSID:  ESP_FBAB38
12:23:08.926 -> *wm:[2] AP has anonymous access! 
12:23:09.412 -> *wm:[1] AP IP address: 192.168.4.1
12:23:09.412 -> *wm:[1] Starting Web Portal 
12:23:09.412 -> *wm:[2] HTTP server started 
12:23:09.412 -> *wm:[2] Config Portal Running, non blocking/processing 
12:23:09.412 -> *wm:[2] Portal Timeout In 60 seconds
12:23:37.118 -> *wm:[2] Portal Timeout In 31 seconds
12:24:07.126 -> *wm:[2] Portal Timeout In 1 seconds
12:24:08.396 -> *wm:[1] config portal has timed out 
12:24:08.396 -> *wm:[2] shutdownConfigPortal 
12:24:08.396 -> *wm:[2] restoring usermode STA
12:24:09.398 -> *wm:[2] WiFi Reconnect, was idle 
12:24:09.444 -> *wm:[2] wifi status: WL_IDLE_STATUS
12:24:09.444 -> *wm:[2] wifi mode: STA
12:24:09.444 -> *wm:[2] configportal closed

This is my current code (100% from the examples)

#include <WiFiManager.h>

const char* wifiAutoSSID = "NCC1701D";

WiFiManager wm;

void setup() {
    WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP    
    // put your setup code here, to run once:
    Serial.begin(115200);
    
    //reset settings - wipe credentials for testing
    wm.resetSettings();

    wm.setConfigPortalBlocking(false);
    wm.setConfigPortalTimeout(60);
    //automatically connect using saved credentials if they exist
    //If connection fails it starts an access point with the specified name
    if(wm.autoConnect(wifiAutoSSID)){
        Serial.println("connected...yeey :)");
    }
    else {
        Serial.println("Configportal running");
    }

    wm.startConfigPortal();
    // wm.startWebPortal();
}

void loop() {
    //wm.process();
    // put your main code here, to run repeatedly:
}

I am using an ESP 8266 based WeMos D1 R2 ... if that may help?!

@tablatronix
Copy link
Collaborator

wm.startConfigPortal(wifiAutoSSID);

`

@ChristophCaina
Copy link
Author

ChristophCaina commented Mar 11, 2022

Hi, just another question so far:

Can you please explain, why this seems to run in a loop?

12:23:07.388 -> *wm:[1] No Credentials are Saved, skipping connect 
12:23:07.388 -> *wm:[2] Starting Config Portal 
12:23:07.388 -> *wm:[2] Disabling STA 
12:23:07.388 -> *wm:[2] Enabling AP 
12:23:07.388 -> *wm:[1] StartAP with SSID:  NCC1701D
12:23:07.899 -> *wm:[2] AP has anonymous access! 
12:23:08.385 -> *wm:[1] AP IP address: 192.168.4.1
12:23:08.385 -> *wm:[1] Starting Web Portal 
12:23:08.385 -> *wm:[2] HTTP server started 
12:23:08.385 -> *wm:[2] Config Portal Running, non blocking/processing 
12:23:08.421 -> *wm:[2] Portal Timeout In 60 seconds
12:23:08.421 -> Configportal running

and after that, it is starting again with:

12:23:08.421 -> *wm:[2] Starting Config Portal 
12:23:08.421 -> *wm:[2] Disabling STA 
12:23:08.421 -> *wm:[2] Enabling AP 
12:23:08.421 -> *wm:[1] StartAP with SSID:  NCC1701D
12:23:08.926 -> *wm:[2] AP has anonymous access! 
12:23:09.412 -> *wm:[1] AP IP address: 192.168.4.1
12:23:09.412 -> *wm:[1] Starting Web Portal 
12:23:09.412 -> *wm:[2] HTTP server started 
12:23:09.412 -> *wm:[2] Config Portal Running, non blocking/processing 
12:23:09.412 -> *wm:[2] Portal Timeout In 60 seconds

The code is still the same as given in the Example sketch I've mentioned above... (with the fix provided in your previous comment)

and what does the [x] after wm: mean?
Is this the instance of the wm or is this some kind of log-level?

@tablatronix
Copy link
Collaborator

tablatronix commented Mar 11, 2022

Yes, Its the logging level

you are calling wm.resetSettings(); on every boot.

@tablatronix tablatronix added the Question User Question member to member support label Mar 11, 2022
@ChristophCaina
Copy link
Author

ok, thanks.
the "reset" was due to current development - and I want to reset the settings on each "reboot" of the board... but the current behave happens without any reboot (at least, I don't see the board rebooting)...

it's just immediately visible after uploading the code to the board... then it is running throught 1) and immediately the second block happens.

So, is the chip rebooting when it could not connect to an existing network / no network information can be found?

@tablatronix
Copy link
Collaborator

ohh let me check if this is a bug, you have non blocking false but commented out process ? thats wrong

@ChristophCaina
Copy link
Author

process was just commented out for a test when I copied the code :)

@tablatronix
Copy link
Collaborator

tablatronix commented Mar 11, 2022

There is no other serial output between those? I mean it totally looks like its restarting
add a println starting.... to the setup

where does this come from ?
12:23:08.421 -> Configportal running

@ChristophCaina
Copy link
Author

that's from this code...
I have just used the code given in the example without any further changes...

    if(wm.autoConnect(wifiAutoSSID)){
        Serial.println("connected...yeey :)");
    }
    else {
        Serial.println("Configportal running");
    }

@ChristophCaina
Copy link
Author

ChristophCaina commented Mar 12, 2022

Maybe, a bit more information:

As you can see in my first post, it was first starting with the SSID I've set in the wm.autoConnect() - but then printing the serial.println from the "else" statement.
Immediately after that, it "restarted" and used the wm.startConfigPortal(); where I haven't used my SSID - and due to that, it took the default ESP..... whatever SSID.

in my tests, I've commented the wm.process() from the loop out, to see, if that might cause this behave - but it didn't change anything

@tablatronix
Copy link
Collaborator

Oh yeah i ran this and it works fine. So no clue, sounds like your esp has to be rebooting

@ChristophCaina
Copy link
Author

hm... thanks for your test.
Would you be so kind and share your code & serial output, that I can compare it and run another test?
I would really like to understand what my ESP is doing here - and therefore trying to figure out, how I could extend / debug this on my side...

@tablatronix
Copy link
Collaborator

Add a println in setup that outputs millis() it should be obvious is it restarts, could be a brownout all these should show startup code in serial though… so its odd i ran your example exactly

@ChristophCaina
Copy link
Author

hm... sorry... no reboot during the startup:

19:44:22.114 -> 69                                               // first millis() println
19:44:22.214 -> *wm:[1] AutoConnect 
19:44:22.214 -> *wm:[1] No Credentials are Saved, skipping connect 
19:44:22.214 -> *wm:[2] Starting Config Portal 
19:44:22.214 -> *wm:[2] AccessPoint set password is VALID 
19:44:22.214 -> *wm:[2] Disabling STA 
19:44:22.214 -> *wm:[2] Enabling AP 
19:44:22.214 -> *wm:[1] StartAP with SSID:  ****                              // This time, I am using an existing SSID with Passwort in the AutoConnect(); part
19:44:24.093 -> *wm:[1] AP IP address: 192.168.4.1
19:44:24.093 -> *wm:[1] Starting Web Portal 
19:44:24.093 -> *wm:[2] HTTP server started 
19:44:24.093 -> *wm:[2] Config Portal Running, non blocking/processing 
19:44:24.093 -> *wm:[2] Portal Timeout In 60 seconds
19:44:24.093 -> Configportal running                                   // Portal is running
19:44:24.093 -> *wm:[2] Starting Config Portal                     // Starting configPortal aain
19:44:24.093 -> *wm:[2] Disabling STA 
19:44:24.093 -> *wm:[2] Enabling AP 
19:44:24.093 -> *wm:[1] StartAP with SSID:  NCC1701D      // using the SSID I've set up in the wm.StartConfigPortal();
19:44:24.595 -> *wm:[2] AP has anonymous access! 
19:44:25.114 -> *wm:[1] AP IP address: 192.168.4.1
19:44:25.114 -> *wm:[1] Starting Web Portal 
19:44:25.114 -> *wm:[2] HTTP server started 
19:44:25.114 -> *wm:[2] Config Portal Running, non blocking/processing 
19:44:25.114 -> *wm:[2] Portal Timeout In 60 seconds
19:44:25.114 -> 
19:44:25.114 -> Setup END
19:44:52.041 -> *wm:[2] Portal Timeout In 32 seconds
19:45:22.072 -> *wm:[2] Portal Timeout In 2 seconds
19:45:24.075 -> *wm:[1] config portal has timed out 
19:45:24.111 -> *wm:[2] shutdownConfigPortal 
19:45:24.111 -> *wm:[2] restoring usermode STA
19:45:25.108 -> *wm:[2] WiFi Reconnect, was idle 
19:45:25.108 -> *wm:[2] wifi status: WL_IDLE_STATUS
19:45:25.108 -> *wm:[2] wifi mode: STA
19:45:25.108 -> *wm:[2] configportal closed 

@tablatronix
Copy link
Collaborator

tablatronix commented Mar 14, 2022

Oh thats so odd.. is this an esp32 ?

@tablatronix
Copy link
Collaborator

Is this with process?

@tablatronix
Copy link
Collaborator

nm, I have it reproduced here!

@tablatronix tablatronix reopened this Mar 14, 2022
@tablatronix tablatronix added bug Validated BUG and removed Question User Question member to member support labels Mar 14, 2022
@tablatronix tablatronix changed the title Example is starting configuration Portal and AP Mode with specific SSID -> Then starting again with auto-generated SSID ?! Example is starting configuration Portal twice Mar 14, 2022
@tablatronix
Copy link
Collaborator

I mean this is technically not a bug, you are just starting the CP twice, which should be ok say you want to change the credentials, but I am going to add a check and fail to avoid confusion.

tablatronix added a commit that referenced this issue Mar 14, 2022
@ChristophCaina
Copy link
Author

thanks :) - and sorry for not replying directly... (timezones^^)

it is an WeMos D1 R2 (ESP8266), it was with wm.process() - but the same applies without wm.process();

The main idea (and I think that's what this cp is for was):
To provide the cp to allow a customer to change the "default" WiFi Settings to his own WiFi - therefore, there's no reason to start the CP twice, when it can't find any saved credentials.

So, yes, while it shouldn't be a big issue - it was confusing a bit :)
Thanks for having a look into it again - really appreciated (y)
Now, I need to see how I can setup the CP websites itself... ^^

@tablatronix
Copy link
Collaborator

tablatronix commented Mar 14, 2022

Yeah the example is confusing and wrong, ill update it also.

Not sure what was going on there, but yeah autoconnect will do that automatically unless you use the option to disable it.

@ChristophCaina
Copy link
Author

ChristophCaina commented Mar 14, 2022

one more question:
How can I print the SSID of the "configPortal" when it is connected / started?
I read something about WiFi.SSID() ... but not sure, if this is working within the ConfigPortal() too, or only when it could connect to a stored WiFi...

And would this work?

  if(wm.autoConnect()) {
    if(debug) {
      Serial.print("successfully connected to: ");
      Serial.println(WiFi.SSID());
    }
  }
  else {
    if(wm.startConfigPortal(wifiAutoSSID)) {
      if(debug) {
        Serial.print("configuration portal started");
      }
    }
    else {
      if(debug) {
        Serial.print("failed to launch configuration portal");
        Serial.println("restarting device!");
      }
      esp.restart();

So, I would expect, the manager is trying to do an AutoConnect() to the saved network - and if this should fail, it will start the CP with the specified "autoSSID"...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Validated BUG
Projects
None yet
Development

No branches or pull requests

2 participants