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