From 89b158f3d1d51dcc76be6da4472b91c25545a2bd Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 21 Nov 2020 22:20:15 +0100 Subject: [PATCH 1/3] cut timeouts shorter --- WifiInterface.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 8020d85..fce1f42 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -178,7 +178,7 @@ wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __F if (checkForOK(5000, (const char*) F("+CIFSR:STAIP"), true,false)) if (!checkForOK(1000, (const char*) F("0.0.0.0"), true,false)) ipOK = true; - } else { + } else { // Should this really be "else" here /haba if (!ipOK) { @@ -191,7 +191,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(16000, OK_SEARCH, true); + ipOK = checkForOK(8000, OK_SEARCH, true); } DIAG(F("\n**\n")); @@ -203,10 +203,9 @@ 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(20000, OK_SEARCH, true); + ipOK = checkForOK(8000, OK_SEARCH, true); } } - delay(8000); // give a preconfigured ES8266 a chance to connect to a router if (ipOK) { // But we really only have the ESSID and password correct @@ -244,7 +243,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(16000, OK_SEARCH, true)); // do twice if necessary but ignore failure as AP mode may still be ok + while (i++<2 && !checkForOK(8000, OK_SEARCH, true)); // do twice if necessary but ignore failure as AP mode may still be ok } else { @@ -257,17 +256,17 @@ wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __F } StringFormatter::send(wifiStream, F("AT+CIPSERVER=0\r\n")); // turn off tcp server (to clean connections before CIPMUX=1) - checkForOK(10000, OK_SEARCH, true); // ignore result in case it already was off + checkForOK(1000, OK_SEARCH, true); // ignore result in case it already was off StringFormatter::send(wifiStream, F("AT+CIPMUX=1\r\n")); // configure for multiple connections - if (!checkForOK(10000, OK_SEARCH, true)) return WIFI_DISCONNECTED; + if (!checkForOK(1000, OK_SEARCH, true)) return WIFI_DISCONNECTED; StringFormatter::send(wifiStream, F("AT+CIPSERVER=1,%d\r\n"), port); // turn on server on port - if (!checkForOK(10000, OK_SEARCH, true)) return WIFI_DISCONNECTED; + if (!checkForOK(1000, OK_SEARCH, true)) return WIFI_DISCONNECTED; #endif //DONT_TOUCH_WIFI_CONF StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); // Display ip addresses to the DIAG - if (!checkForOK(10000, OK_SEARCH, true, false)) return WIFI_DISCONNECTED; + if (!checkForOK(1000, OK_SEARCH, true, false)) return WIFI_DISCONNECTED; DIAG(F("\nPORT=%d\n"),port); return WIFI_CONNECTED; From a3ddcb059a0f7c8f0e410aeda695882f3293be70 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 21 Nov 2020 23:23:27 +0100 Subject: [PATCH 2/3] make connection timeout configurable --- WifiInterface.cpp | 11 +++++++---- config.example.h | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) 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 ///////////////////////////////////////////////////////////////////////////////////// // From 31022094c11ccfbdee7eb15d772f1559005aa8df Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Mon, 23 Nov 2020 00:46:14 +0100 Subject: [PATCH 3/3] adjust timeouts --- WifiInterface.cpp | 7 ++++--- config.example.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 3e9a0f0..a80481c 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -35,7 +35,8 @@ bool WifiInterface::connected = false; Stream * WifiInterface::wifiStream; #ifndef WIFI_CONNECT_TIMEOUT -#define WIFI_CONNECT_TIMEOUT 8000 +// Tested how long it takes to FAIL an unknown SSID on firmware 1.7.4. +#define WIFI_CONNECT_TIMEOUT 14000 #endif //////////////////////////////////////////////////////////////////////////////// @@ -175,8 +176,8 @@ 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(WIFI_CONNECT_TIMEOUT); // give a preconfigured ES8266 a chance to connect to a router - + delay(8000); // give a preconfigured ES8266 a chance to connect to a router + // typical connect time approx 7 seconds StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); if (checkForOK(5000, (const char*) F("+CIFSR:STAIP"), true,false)) if (!checkForOK(1000, (const char*) F("0.0.0.0"), true,false)) diff --git a/config.example.h b/config.example.h index d3542d6..a6412bc 100644 --- a/config.example.h +++ b/config.example.h @@ -56,10 +56,10 @@ The configuration file for DCC++ EX Command Station // ///////////////////////////////////////////////////////////////////////////////////// // -// Wifi connect timeout in milliseconds. Default is 8000 (8 seconds). You only need +// Wifi connect timeout in milliseconds. Default is 14000 (14 seconds). You only need // to set this if you have an extremely slow Wifi router. // -//#define WIFI_CONNECT_TIMEOUT 8000 +//#define WIFI_CONNECT_TIMEOUT 14000 ///////////////////////////////////////////////////////////////////////////////////// //