-->
Page 1 of 1

OTA+Webserver issues in AP_STA Mode with STA disconnected

PostPosted: Wed Feb 17, 2021 2:59 pm
by RFZ
Hi,
I'm booting the ESP in AP_STA mode and usually it connects to my Wifi. I'm using ArduinoOTA and the Webserver to serve a User-Interface or, if required, a captive portal to set new Wifi credentials.
Server and OTA work fine when the ESP is connected to my Wifi, either via its STA IP or directly connected to its AP.
However, when the ESP is not connected (e.g. the wifi credentials changed ir the SSID is unavailable) the AP still works, but the Webserver is unreliable and OTA breaks during the upload.

I guess this is because the ESP is hopping channels to search for the SSID it is configured to connect to, losing the connection to the associated client.

So: What is the best way solve this issue? Can I temporary disable channel-hopping / auto-reconnect while a client is connected to the ESPs AP? Or should I change the mode from AP_STA to AP as soon a client connects?
I don't have clients connected to the AP on a regular basis in my use-case. It is just used for OTA or to set new wifi credentials in case they changed.

I haven't found anything about this in the docs or OTA examples.

Any recommendations?

Re: OTA+Webserver issues in AP_STA Mode with STA disconnecte

PostPosted: Wed Feb 17, 2021 5:35 pm
by btidey
Unless you want both AP and STA to be operational for other reasons then it may be better to use WifiManager or one of its offspring to manage the entering of wifi credentials both initially or when something changes.

WifiManager tries to connect STA using previous credentials. If this fails then it activates AP to allow a browser client to log in and enter credentials. It then reverts back to STA mode.

Re: OTA+Webserver issues in AP_STA Mode with STA disconnecte

PostPosted: Fri Feb 19, 2021 3:11 pm
by RFZ
Yeah, I really don't like WifiManager... I want the same interface for setting wifi credentials even when it is already connected.

Using this, works fine so far:

Code: Select all   if(WiFi.softAPgetStationNum() > 0 && WiFi.getMode() == WIFI_AP_STA && !WiFi.isConnected()) {
      WiFi.mode(WIFI_AP);
      Serial.println("Station connected, switching to AP mode!");
   }
   if(WiFi.softAPgetStationNum() == 0 && WiFi.getMode() == WIFI_AP) {
      WiFi.mode(WIFI_AP_STA);
      WiFi.reconnect(); // won't reconnect without that
      Serial.println("Station disconnected, switching to AP+STA mode!");
   }