diff --git a/WifiInterface.cpp b/WifiInterface.cpp index fce1f42..3e9a0f0 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -34,6 +34,9 @@ const unsigned long LOOP_TIMEOUT = 2000; bool WifiInterface::connected = false; Stream * WifiInterface::wifiStream; +#ifndef WIFI_CONNECT_TIMEOUT +#define WIFI_CONNECT_TIMEOUT 8000 +#endif //////////////////////////////////////////////////////////////////////////////// // @@ -172,7 +175,7 @@ wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __F // ESP8266 is preconfigured. We check the first 13 chars // of the password. if (strncmp_P("Your network ",(const char*)password,13) == 0) { - delay(8000); // give a preconfigured ES8266 a chance to connect to a router + delay(WIFI_CONNECT_TIMEOUT); // give a preconfigured ES8266 a chance to connect to a router StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); if (checkForOK(5000, (const char*) F("+CIFSR:STAIP"), true,false)) @@ -191,7 +194,7 @@ wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __F // AT command early version supports CWJAP/CWSAP if (SSid) { StringFormatter::send(wifiStream, F("AT+CWJAP=\"%S\",\"%S\"\r\n"), SSid, password); - ipOK = checkForOK(8000, OK_SEARCH, true); + ipOK = checkForOK(WIFI_CONNECT_TIMEOUT, OK_SEARCH, true); } DIAG(F("\n**\n")); @@ -203,7 +206,7 @@ wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __F if (SSid) { StringFormatter::send(wifiStream, F("AT+CWJAP_CUR=\"%S\",\"%S\"\r\n"), SSid, password); - ipOK = checkForOK(8000, OK_SEARCH, true); + ipOK = checkForOK(WIFI_CONNECT_TIMEOUT, OK_SEARCH, true); } } @@ -243,7 +246,7 @@ wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __F int i=0; do StringFormatter::send(wifiStream, F("AT+CWSAP=\"DCCEX_%s\",\"PASS_%s\",1,4\r\n"), macTail, macTail); - while (i++<2 && !checkForOK(8000, OK_SEARCH, true)); // do twice if necessary but ignore failure as AP mode may still be ok + while (i++<2 && !checkForOK(WIFI_CONNECT_TIMEOUT, OK_SEARCH, true)); // do twice if necessary but ignore failure as AP mode may still be ok } else { diff --git a/config.example.h b/config.example.h index 3ceb675..d3542d6 100644 --- a/config.example.h +++ b/config.example.h @@ -53,6 +53,13 @@ The configuration file for DCC++ EX Command Station #define WIFI_SSID "Your network name" #define WIFI_PASSWORD "Your network passwd" #define WIFI_HOSTNAME "dccex" +// +///////////////////////////////////////////////////////////////////////////////////// +// +// Wifi connect timeout in milliseconds. Default is 8000 (8 seconds). You only need +// to set this if you have an extremely slow Wifi router. +// +//#define WIFI_CONNECT_TIMEOUT 8000 ///////////////////////////////////////////////////////////////////////////////////// //