Wifi connection, What's wrong

Hello everyone, please help.
Doing something wrong and can't figure out what!!

I want to retry the Wi-Fi connection 30 times,
If you have success before, continue the program
If not, continue without wifi

HELP :slight_smile:

void setup() {
  Wire.begin(5, 4);
  byte retry = 0;
  byte maxRetries = 31;
  pinMode(ledpin, OUTPUT);
  digitalWrite(ledpin, ledon);
#ifdef DEBUG
  Serial.begin(74880);
#endif
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  WiFi.begin(ssid, password);
  delay(1000);
  while ((WiFi.status() != WL_CONNECTED) || (retry > maxRetries)) {
    retry++;
    delay(500);
    toggleLED();
#ifdef DEBUG
    Serial.print(retry);
    Serial.print("-");
    Serial.print(WiFi.status());
    Serial.println();
#endif

while ((WiFi.status() != WL_CONNECTED) && (retry < maxRetries))

Thank you!
I thought that was my first try and didn't work. For sure was doing something wrong because não it's working.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.