Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By JohnSL
#27971 It seems like there is some incorrect behavior with the WiFi instance when using the SDK's auto reconnect mode. I believe this has to do with the _useClientMode and _useApMode variables, as they are set to false on startup.

My application is currently running in WIFI_AP_STA when it starts up (without me making any calls to WiFi). That means both of these variables should be set to true based on the actual mode of the ESP. The SDK seems to remember these settings, as well as the SSID and password to use when connecting as a station.

So when I call a method like WiFi.softAP to change the AP name, or WiFi.scanNetworks to see what's out there, it changes the mode, using code like this in ESP8266WiFi.cpp for softAP:

Code: Select all    if(_useClientMode) {
        // turn on AP+STA mode
        mode(WIFI_AP_STA);
    } else {
        // turn on STA mode
        mode(WIFI_AP);
    }

and this for scanNetworks:

Code: Select all    if(_useApMode) {
        // turn on AP+STA mode
        mode(WIFI_AP_STA);
    } else {
        // turn on STA mode
        mode(WIFI_STA);
    }

So in one case it turns off my station mode, and in the other case it turns off my AP mode.

I was able to make this work the way I would expect by adding three lines to the constructor:

Code: Select allESP8266WiFiClass::ESP8266WiFiClass()
: _smartConfigStarted(false)
, _smartConfigDone(false)
, _useApMode(false)
, _useClientMode(false)
, _useStaticIp(false)
{
    uint8 m = wifi_get_opmode();
    _useClientMode = (m & WIFI_STA);
    _useApMode = (m & WIFI_AP_STA);
    wifi_set_event_handler_cb((wifi_event_handler_cb_t)&ESP8266WiFiClass::_eventCallback);
}


Is there any reason the constructor should not be changed in this way? I'm guessing something similar should also be done for _useStaticIp, but I don't use a static IP, so I haven't done any testing on that.