Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Zero_PD
#46344 Thanks guys, you were right. I didn't think about doing a timeout (which would probably be a lot cleaner), but I made a "for" loop which tried five times to connect four or five times, and I found that on the 3rd or 4th try it worked! I'm a little confused by the timeout code. Don't you have to be trying to connect again by using the WiFi.begin command?

Code: Select allvoid setup()
{
 Serial.begin(9600);
 Serial.println("serial begin");
 delay(500);
 status = WiFi.begin(ssid);
 delay(500);
 Serial.println("past wifi begin");

 if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    //while(true);
    Serial.println("About to go into for loop");
    for (int i=0; i<5; i++){
      Serial.println("Trying to connect again");
      tryagain();
      if ( status != WL_CONNECTED){Serial.println("Not Connected");}
      else if (status == WL_CONNECTED){
        Serial.println("Connected");
        break;
        }
    }
  }

}

void loop () {
  Serial.println("Lost in loop");
  Serial.println(status);
  delay(1000);
  }

void tryagain(void){
  delay(1000);
  status = WiFi.begin(ssid, pass);
  delay(1000);
}
User avatar
By Zero_PD
#46355 Ah I see. Does that mean in the background it is automatically trying to connect multiple times, or is it simply that the wifi.begin connect function takes a long time and you need to wait and see if it worked?

I'm used to everything happening in micro to milliseconds max.
User avatar
By martinayotte
#46393 Nope ! Previous begin() are simply aborted !
But lets do a comparison :
If you take your phone and dial a number and you simply hangup within few second and try new redial again, there not a lot of chance that you will get a connection if you don't wait enough for the other person to answer... :ugeek: