Chat freely about anything...

User avatar
#90560 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?
User avatar
By btidey
#90563 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.
User avatar
#90585 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()) {
      Serial.println("Station connected, switching to AP mode!");
   if(WiFi.softAPgetStationNum() == 0 && WiFi.getMode() == WIFI_AP) {
      WiFi.reconnect(); // won't reconnect without that
      Serial.println("Station disconnected, switching to AP+STA mode!");