How to handle Disconnects to router
Posted: Sat Oct 24, 2015 1:17 pm
Hi,
I've a problem with my current sketch and connection to my local Network. On Boot I load config from EEPROM and connect to my Router (AVM FritzBox):
In the beginning everything works fine. Serial.prinln shows me "WL_CONNECTED" but after a while (3-10 Minutes) I get "WL_CONNECT_FAILED" followed by "WL_DISCONNECTED". So if this happens I want to reconnect to my router and this fails.
So my question is: How to deal with that and how to be able to stay connected? if I use WiFiServer instead of ESP8266WebServer it stays connected over 1 hour, so my router isn't the problem but I can't use server.on() or other functions I'm useing so only way is to rewrite everything which can't be the solution I think...
Greetings Moritz
I've a problem with my current sketch and connection to my local Network. On Boot I load config from EEPROM and connect to my Router (AVM FritzBox):
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
...
ESP8266WebServer server ( 80 );
...
void setup() {
setupWifi();
server.on("/", handleRoot);
server.on ( "/style.css", []() {
Serial.println("Page: Style.css");
server.send ( 200, "text/css", PAGE_Style_css );
} );
server.on("/time", htmlTime);
server.on("/temp", htmlTemp);
server.begin();
Serial.println("HTTP server started");
}
void setupWifi() {
Serial.println ( "Setup Wifi" );
if (EspLoadSettings()) {
// Wait for connection
byte tries = 22;
WiFi.scanNetworks();
WiFi.mode(WIFI_AP_STA);
WiFi.begin ( SSID , PASS );
Serial.println ( "Connecting to router" );
Serial.println ( SSID );
Serial.println ( PASS );
while (--tries && WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print ( "." );
}
delay(500);
Serial.println ( "" );
Serial.print ( "Connected to " );
Serial.println ( genSettings.rSSID );
Serial.print ( "IP address: " );
Serial.println ( WiFi.localIP() );
}
}
void loop()
{
server.handleClient();
if(WiFi.status()==WL_IDLE_STATUS){
Serial.println("WL_IDLE_STATUS");
}else if(WiFi.status()==WL_NO_SSID_AVAIL){
Serial.println("WL_NO_SSID_AVAIL");
}else if(WiFi.status()==WL_SCAN_COMPLETED){
Serial.println("WL_SCAN_COMPLETED");
}else if(WiFi.status()==WL_CONNECTED){
Serial.println("WL_CONNECTED");
}else if(WiFi.status()==WL_CONNECT_FAILED){
Serial.println("WL_CONNECT_FAILED");
}else if(WiFi.status()==WL_CONNECTION_LOST){
Serial.println("WL_CONNECTION_LOST");
}else if(WiFi.status()==WL_DISCONNECTED){
Serial.println("WL_DISCONNECTED");
}
if (WiFi.status() == WL_DISCONNECTED ) {
???????????????????????????????????????????ß
}
}
In the beginning everything works fine. Serial.prinln shows me "WL_CONNECTED" but after a while (3-10 Minutes) I get "WL_CONNECT_FAILED" followed by "WL_DISCONNECTED". So if this happens I want to reconnect to my router and this fails.
So my question is: How to deal with that and how to be able to stay connected? if I use WiFiServer instead of ESP8266WebServer it stays connected over 1 hour, so my router isn't the problem but I can't use server.on() or other functions I'm useing so only way is to rewrite everything which can't be the solution I think...
Greetings Moritz