1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +01:00

make connection timeout configurable

This commit is contained in:
Harald Barth 2020-11-21 23:23:27 +01:00
parent 89b158f3d1
commit a3ddcb059a
2 changed files with 14 additions and 4 deletions

View File

@ -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 {

View File

@ -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
/////////////////////////////////////////////////////////////////////////////////////
//