Auto Reconnect to Station without disconnecting AP

esp1979
Posts: 21
Joined: Sun Dec 12, 2021 8:55 pm

Auto Reconnect to Station without disconnecting AP

Postby esp1979 » Mon Dec 20, 2021 7:19 am

Hello,

my sketch uses WIFI_AP_STA as WiFi mode.
The AP setup works fine, but the connection to the station is sometimes lost.
As I know by now, unlike the ESP8266, the ESP32 does not then automatically connect to the station after losing the wifi connection.

So I wonder: what is the correct way to re-trigger the connection with the station?

I often read that a reboot would be the best way or this way:

wifi.disconnect();
wifi.begin();

or

wifi.disconnect();
wifi.reconnect();

But:
If I do a WiFi.disconnect(), my AP will also be terminated, right?
And I want to keep the AP always up and reconnect only the STA.

So I decided to use this variant:

Code: Select all

if (WiFi.status() != WL_CONNECTED) {
      if (millis() - reconnmillis > reconn_timer) {
        WiFi.begin(ssid, password);
        unsigned long pause=5000;
        unsigned long connTimer = millis();
        while (WiFi.status() != WL_CONNECTED && (millis()-connTimer < pause)) {
          delay(500);
          yield();
        }
        reconnmillis = millis();
      }
    }
Is this ok or is it bad to use a Wifi.begin() without a previous Wifi.disconnect()?

Thanks already for your help

Best wishes

Daniel

esp1979
Posts: 21
Joined: Sun Dec 12, 2021 8:55 pm

Re: Auto Reconnect to Station without disconnecting AP

Postby esp1979 » Tue Dec 21, 2021 7:34 pm

Is there really no one that can help me? ;-(
Please...

MakerMan
Posts: 9
Joined: Wed Dec 22, 2021 8:01 pm

Re: Auto Reconnect to Station without disconnecting AP

Postby MakerMan » Thu Dec 23, 2021 3:17 pm

I don't have a definitive answer, but a couple of thoughts which might stimulate some debate ...

Have you tried the options "WiFi.setAutoReconnect(true) and WiFi.persistent(true) to see if that will force auto-reconnect?

Did WiFi.reconnect() not work? Was that why you're looking at WiFi.disconnect() followed by WiFi.begin(ssid, password)?

esp1979
Posts: 21
Joined: Sun Dec 12, 2021 8:55 pm

Re: Auto Reconnect to Station without disconnecting AP

Postby esp1979 » Sat Dec 25, 2021 7:09 pm

Hi,


WiFi.setAutoReconnect(true) does the job, perfect.
I set WiFi.persistent(false) so that ESP does not write ssid and password to flash on every connect.

Best wishes and merry christmas.

Daniel

Who is online

Users browsing this forum: No registered users and 44 guests