Arduino Mbed OS - switching between WiFi's STA & AP modes

Hello everybody,

When using an Arduino GIGA R1 WiFi -- but maybe this is similar in Portenta H7 and other Arduino boards running Mbed OS, -- I do not understand what is the right way to switch between STA mode and AP mode, repeatedly. (STA connection, if fails -> AP, captive portal to ask WiFi credentials, iterate).

When STA connection fails at first, depending on the reasons for the failure (SSID not found, incorrect password, correct credentials yet connection failure...), AP creations may succeed or not (usually, succeeds if SSID is not found, fails otherwise and from second iteration), and WiFiUDP also is likely to fail sending packets (packets received, but WiFiUDP::endPacket() fails).

Whenever I switch between STA & AP, I currently invoke WiFiUDP::stop() and do the following

WiFi.end();
delay(20);    // might a delay help?
WiFi = WiFiClass(WiFiInterface::get_default_instance());   // TODO: is it safe? Is it necessary?
delay(35);    // might a delay help?

WiFiUDP::begin(port) is then called again later when AP is opened.

Rather than asking help with my specific (complex) code, I would appreciate any general suggestion, as I do not find detailed docs about how to use such libraries.

This question is much related to GitHub issue GIGA R1 - WiFi.begin(), WiFi.beginAP, & WiFiUDP issues · Issue #1040 · arduino/ArduinoCore-mbed · GitHub I have just opened.

Thank you very much for your help

I am not an expert on WiFi or on C++, but are you not trying to create another new object of the WiFi class? That seems wrong to me. I would look at other libraries, and I mean builtin, not some random github repo.

Actually, the creation of a new Wi-Fi object was an attempt to somehow reset the object itself, which proved to be useful in the past.

Also, I am using built-in library, which is being developed through the GitHub project I linked

Ok, since you are now working with the development team, I will bow out.