hello, so i have this code on arduino nano rp2040 Connect that tries to connect to a wifi to read the rssi then disconnect and goes for a second wifi to do the same, here the code :
currentMillis=millis();
output = "";
attemptConnection(SSID_WIFI1, PASSWORD_WIFI1, output);
String tempOutput = "";
attemptConnection(SSID_WIFI2, PASSWORD_WIFI2, tempOutput);
output+=tempOutput;
// Pad the response string with spaces until it reaches 10 characters
while (output.length() < 15) {
output += ' ';
}
command = '\0'; // Reset command after processing
Serial.println(millis()-currentMillis);
as for the function attemptConnection :
void attemptConnection(const char* ssid, const char* password, String &chaine) {
unsigned long startTime, endTime;
if (WiFi.status() == WL_CONNECTED) {
WiFi.disconnect();
delay(100);
}
WiFi.begin(ssid, password);
int attempts = 0; // Reset attempts counter
while (WiFi.status() != WL_CONNECTED && attempts < MAX_wifi_try) {
delay(DELAI_essaie);
digitalWrite(LEDR, HIGH); // Turn on RED LED
digitalWrite(LEDB, LOW); // Turn off BLUE LED
attempts++;
}
if (WiFi.status() == WL_CONNECTED) {
digitalWrite(LEDB, HIGH); // Turn on BLUE LED
digitalWrite(LEDR, LOW); // Turn off RED LED
long rssi = WiFi.RSSI();
chaine = String(rssi) + ",";
} else {
digitalWrite(LEDR, HIGH); // Turn on RED LED
digitalWrite(LEDB, LOW); // Turn off BLUE LED
chaine = "KO,";
}
}
the delay between each try is 300 ms, and max try is set to 2 so in total 300 ms, after several tries i saw that the code block take times that varies from 3 second to 10 seconds ! which is too much , can anyone explain this variability ? mainly witnessing in Wifi.begin and Wifi.disconnect, i m doing something wrong in the code to note have consistent execution time ? and thanks in advance for help.