-->
Page 1 of 3

WiFi retry connect, how ?

PostPosted: Thu Jan 14, 2016 2:48 pm
by donnib
Hi,
I have this construction :
Code: Select allvoid LaunchWifi()
{
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  WiFi.config(ip,gateway,subnet);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}


and sometimes it ends up in the while and never connects, if i reboot the device it usually works so what is the best approach to wait say 5sec then retry to connect from start again ?

donnib

Re: WiFi retry connect, how ?

PostPosted: Thu Jan 14, 2016 6:10 pm
by Mario Mikočević
Try this ->

Code: Select all  if( !WiFi.isConnected() ) {
    Serial.println( "Disconnected!" );
    WiFi.reconnect();
    WiFi.waitForConnectResult();
  }

Re: WiFi retry connect, how ?

PostPosted: Fri Jan 15, 2016 2:58 am
by donnib
Mario Mikočević wrote:Try this ->

Code: Select all  if( !WiFi.isConnected() ) {
    Serial.println( "Disconnected!" );
    WiFi.reconnect();
    WiFi.waitForConnectResult();
  }


Thx but i don't have WiFi.isConnected(), in which library is that ?

Re: WiFi retry connect, how ?

PostPosted: Fri Jan 15, 2016 9:36 am
by martinayotte
ESP8266WiFi (in ESP8266WiFiSTA.h)