I am developing a project where I need to switch between connecting to an existing network and opening Arduino's Access Point for incoming connections. That is, I need to switch between WiFiClass:begin(...) and WiFiClass:beginAP(...).
The problem is that some libraries (e.g. WiFiClient for TCP communication) do not work properly on my Arduino GIGA R1 wifi, unless I invoke the following:
Then things work, at least for a while. However, I am concerned about the safety of the previous command because the class has pointers inside and it lacks of a deconstructor.
Not an answer to your question but wanted to share (in case you can switch processor) that the ESP32 board can act as Wi-Fi Station, Access Point or both.
To set the Wi-Fi mode, use WiFi.mode() and set the desired mode as argument:
code
description
WiFi.mode(WIFI_STA);
station mode: the ESP32 connects to an access point
WiFi.mode(WIFI_AP);
access point mode: stations can connect to the ESP32
WiFi.mode(WIFI_AP_STA;)
access point and a station connected to another access point
I don't know if it is convenient to make the global variables local, maybe I'll try.
However, the static one must be so due to the use I make of the function. Essentially, that function does a rather long job and I have a blinking LED that I want to keep blinking smoothly (plus checking buttons and other issues). But never mind all that: my question then is:
Why should those variables be local rather than global?
Is there any good documentation where I can learn and understand the best practice with those libraries? I couldn't find any...
Notwithstanding, making WiFiClient variables local did not solve the problem. It is still necessary to clean the WiFi variable to get things work.
Also a local WiFiUDP variable fails if I don't do so.
Then I'll hope WiFi = WiFiClass(WiFiInterface::get_default_instance()) is a safe instruction.