Skip to content

WiFi IP config issues, need WiFi::reset() #1045

Open
@giorgiogallina

Description

@giorgiogallina

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions