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

Moderator: igrr

User avatar
By patman
#41488 I have a fairly simple sketch using ESP8266wifi that reads data from Thingspeak and sets a dry contact relay. In "setup" I use a standard wifi.begin() to connect to a WPA network and it connects just fine. The problem is that in order for me to use the ESP8266 it needs to reconnect to the wifi router again after there is any kind of wifi outage. The problem is it doesn't.

Is it supposed to reconnect automatically after a disconnect?
User avatar
By markus_b
#41555 An easy solution is to check if the connection is still alive, if it is not, then wait a moment , the reboot. When starting it will go again through setup() and connect again. The wait is to make sure it does not too frequently.
User avatar
By Stévanovich
#41740 Hi,

Here is what i use , works for me, maybe not perfect :mrgreen:

Code: Select allvoid WIFI_Connect()
{
  digitalWrite(2,1);
  WiFi.disconnect();
  Serial.println("Booting Sketch...");
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(ssid, password);
    // Wait for connection
  for (int i = 0; i < 25; i++)
  {
    if ( WiFi.status() != WL_CONNECTED ) {
      delay ( 250 );
      digitalWrite(2,0);
      Serial.print ( "." );
      delay ( 250 );
      digitalWrite(2,1);
    }
  }
  digitalWrite(2,0);
}

...
...
..

void setup(void){
  pinMode(2, OUTPUT);
  Serial.begin(115200);
  Serial.println();
  WIFI_Connect();
...
..
..
}

void loop(void){
    if (WiFi.status() != WL_CONNECTED)
    {
      digitalWrite(2,1);
      WIFI_Connect();
    } else {
      digitalWrite(2,0);
    }
...
...
}



Hope will help.
Best regards