arduino / arduino/ArduinoCore-mbed
WiFi IP config issues, need WiFi::reset()
- Dominant language
- C
- Stars
- 411
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
Dear developers,
I am having troubles in switching between WiFi's STA and AP mode on my Arduino GIGA R1 board.
In my scenario, I do the following:
1. I try to connect to some network (STA)
2. If connection fails, I open AP (with random IP address) to ask credentials from user
3. Once credentials are retrieved (or on timeout, or on error), repeat from point 1.
So far I found that:
- `WiFiUDP::endPacket()` often fails with error -3003 (`NSAPI_ERROR_PARAMETER`).
- For some unknown reasons, if I call `IPAddress nullip = IPAddress(); WiFi.config(nullip, nullip, nullip, nullip);` before `WiFi.end()` before STA connection, the latter is incredibly more likely to succeed.
- However, if I do so, `WiFiUDP:endPacket()` always fails as above.
- I found that if I do `WiFi = WiFiClass(WiFiInterface::get_default_instance())` after `WiFi.end()` every time I switch between STA and AP, I have less troubles.
Before AP creation, a random IP address is set as follows:
```
_wifi_ap_ip = IPAddress((char)random(11, 172), (char)random(0, 255), (char)random(0, 255), 0x01);
WiFi.config(_wifi_ap_ip, _wifi_ap_ip, _wifi_ap_ip, IPAddress(255, 255, 255, 0));
```
I used to test my code on a protected network and I experienced fewer problems. Then I had to switch to an open network and a mess arose.
I guess a function like a total **reset** of the WiFi interface with sockets and everything, so to come back to a status as if the Arduino board was just switched on and no connection was attempted, would be advantageous in switching between STA and AP mode.
Thank you
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the STA-to-AP-to-STA sequence on an Arduino GIGA R1, focusing on WiFi.config(), WiFi.end(), WiFiUDP::endPacket(), and reinitializing WiFiClass. Compare behavior with and without the current configuration reset and object recreation. Done would mean a defined reset operation reliably clears the interface and sockets so repeated mode switches and UDP packet sending work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100