Hi all, arduino noobe here. Using MKR 1010 and WiFiNINA library to establish Wifi connectivity.
A number of sample sketches, including Arduino IDE --> File --> Examples --> WiFiNINA --> ConnectWithWPA include a section of Arduino code as follows:
// attempt to connect to WiFi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
My question concerns the statement "delay(10000)."
Why is it necessary to include a delay loop, when the code already includes a WHILE loop that persists until connected (assuming I'm interpreting the code correctly)? Meaning, if the code has verified connection is established, why is it necessary to wait 10 seconds more? Is this an artifact of the library, the hardware, or something else - and is there a more elegant way to write the code instead of the frowned-upon delay method seen here? I'd appreciate your insight. Thank you.