From 46e0fcdc548c52e6bdddcf85b9a6e24f2ef35d24 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 13 Feb 2021 16:15:46 +0000 Subject: [PATCH 01/10] fix wifi setup issue --- WifiInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 5b3a062..673d59c 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -251,8 +251,8 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, } char macTail[]={macAddress[9],macAddress[10],macAddress[12],macAddress[13],macAddress[15],macAddress[16],'\0'}; - while (wifiStream->available()) StringFormatter::printEscape( wifiStream->read()); /// THIS IS A DIAG IN DISGUISE - + checkForOK(1000, OK_SEARCH, true, false); // suck up remainder of AT+CIFSR + i=0; do { if (strncmp_P(yourNetwork, (const char*)password, 13) == 0) { From 5c5a2e924c2526ce189508ae0e1ba71e319cb77a Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 13 Feb 2021 16:16:19 +0000 Subject: [PATCH 02/10] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index e6b7e5a..266c3a0 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "75ab2ab" +#define GITHUB_SHA "46e0fcd" From a8bd530451d27d0cac91e9511d0fdf54360d1b7a Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 13 Feb 2021 17:20:45 +0000 Subject: [PATCH 03/10] Reinstate IP_PORT Arrrrgh! --- CommandStation-EX.ino | 2 +- EthernetInterface.cpp | 4 ++-- EthernetInterface.h | 1 - config.example.h | 6 ++++++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index dbce4e7..4872375 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -69,7 +69,7 @@ void setup() // Start the WiFi interface on a MEGA, Uno cannot currently handle WiFi #if WIFI_ON - WifiInterface::setup(WIFI_SERIAL_LINK_SPEED, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME), 2560); + WifiInterface::setup(WIFI_SERIAL_LINK_SPEED, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME), IP_PORT); #endif // WIFI_ON #if ETHERNET_ON diff --git a/EthernetInterface.cpp b/EthernetInterface.cpp index 2061aa6..38a0b24 100644 --- a/EthernetInterface.cpp +++ b/EthernetInterface.cpp @@ -83,11 +83,11 @@ EthernetInterface::EthernetInterface() IPAddress ip = Ethernet.localIP(); // reassign the obtained ip address - server = new EthernetServer(LISTEN_PORT); // Ethernet Server listening on default port LISTEN_PORT + server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT server->begin(); LCD(4,F("IP: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); - LCD(5,F("Port:%d"), LISTEN_PORT); + LCD(5,F("Port:%d"), IP_PORT); outboundRing=new RingStream(OUTBOUND_RING_SIZE); } diff --git a/EthernetInterface.h b/EthernetInterface.h index 886fc52..87bb8b6 100644 --- a/EthernetInterface.h +++ b/EthernetInterface.h @@ -39,7 +39,6 @@ * */ -#define LISTEN_PORT 2560 // standard listen port for the server #define MAX_ETH_BUFFER 512 #define OUTBOUND_RING_SIZE 2048 diff --git a/config.example.h b/config.example.h index cdad05c..8c25ab9 100644 --- a/config.example.h +++ b/config.example.h @@ -26,6 +26,12 @@ The configuration file for DCC-EX Command Station // #define MOTOR_SHIELD_TYPE STANDARD_MOTOR_SHIELD +///////////////////////////////////////////////////////////////////////////////////// +// +// The IP port to talk to a WIFI or Ethernet shield. +// +#define IP_PORT 2560 + ///////////////////////////////////////////////////////////////////////////////////// // // NOTE: Only supported on Arduino Mega From 79d991db00a0ea2e258d6fa8e5c3330f5cb54c63 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 13 Feb 2021 17:21:43 +0000 Subject: [PATCH 04/10] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 266c3a0..0461db2 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "46e0fcd" +#define GITHUB_SHA "7d72624" From 7e37580466096b1bbcee64e563f739cfb354ee8d Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sun, 14 Feb 2021 13:09:36 +0000 Subject: [PATCH 05/10] Wifi channel and code cleaning --- CommandStation-EX.ino | 2 +- WifiInterface.cpp | 49 +++++++++++++++++++++---------------------- WifiInterface.h | 14 +++++-------- config.example.h | 3 +++ defines.h | 5 ++++- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 4872375..1b08221 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -69,7 +69,7 @@ void setup() // Start the WiFi interface on a MEGA, Uno cannot currently handle WiFi #if WIFI_ON - WifiInterface::setup(WIFI_SERIAL_LINK_SPEED, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME), IP_PORT); + WifiInterface::setup(WIFI_SERIAL_LINK_SPEED, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME), IP_PORT, WIFI_CHANNEL); #endif // WIFI_ON #if ETHERNET_ON diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 673d59c..467b181 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -26,11 +26,8 @@ #include "WifiInboundHandler.h" -const char FLASH READY_SEARCH[] = "\r\nready\r\n"; -const char FLASH OK_SEARCH[] = "\r\nOK\r\n"; -const char FLASH END_DETAIL_SEARCH[] = "@ 1000"; -const char FLASH SEND_OK_SEARCH[] = "\r\nSEND OK\r\n"; -const char FLASH IPD_SEARCH[] = "+IPD"; +#define OK_SEARCH F("\r\nOK\r\n") + const unsigned long LOOP_TIMEOUT = 2000; bool WifiInterface::connected = false; Stream * WifiInterface::wifiStream; @@ -60,7 +57,8 @@ bool WifiInterface::setup(long serial_link_speed, const FSH *wifiESSID, const FSH *wifiPassword, const FSH *hostname, - const int port) { + const int port, + const byte channel) { wifiSerialState wifiUp = WIFI_NOAT; @@ -75,7 +73,7 @@ bool WifiInterface::setup(long serial_link_speed, #if NUM_SERIAL > 0 Serial1.begin(serial_link_speed); - wifiUp = setup(Serial1, wifiESSID, wifiPassword, hostname, port); + wifiUp = setup(Serial1, wifiESSID, wifiPassword, hostname, port, channel); #endif // Other serials are tried, depending on hardware. @@ -83,7 +81,7 @@ bool WifiInterface::setup(long serial_link_speed, if (wifiUp == WIFI_NOAT) { Serial2.begin(serial_link_speed); - wifiUp = setup(Serial2, wifiESSID, wifiPassword, hostname, port); + wifiUp = setup(Serial2, wifiESSID, wifiPassword, hostname, port, channel); } #endif @@ -91,7 +89,7 @@ bool WifiInterface::setup(long serial_link_speed, if (wifiUp == WIFI_NOAT) { Serial3.begin(serial_link_speed); - wifiUp = setup(Serial3, wifiESSID, wifiPassword, hostname, port); + wifiUp = setup(Serial3, wifiESSID, wifiPassword, hostname, port, channel); } #endif @@ -109,7 +107,7 @@ bool WifiInterface::setup(long serial_link_speed, } wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, const FSH* password, - const FSH* hostname, int port) { + const FSH* hostname, int port, byte channel) { wifiSerialState wifiState; static uint8_t ntry = 0; ntry++; @@ -118,7 +116,7 @@ wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, con DIAG(F("\n++ Wifi Setup Try %d ++\n"), ntry); - wifiState = setup2( SSid, password, hostname, port); + wifiState = setup2( SSid, password, hostname, port, channel); if (wifiState == WIFI_NOAT) { DIAG(F("\n++ Wifi Setup NO AT ++\n")); @@ -141,7 +139,7 @@ wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, con #pragma GCC diagnostic ignored "-Wunused-parameter" #endif wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, - const FSH* hostname, int port) { + const FSH* hostname, int port, byte channel) { bool ipOK = false; bool oldCmd = false; @@ -150,9 +148,8 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, // First check... Restarting the Arduino does not restart the ES. // There may alrerady be a connection with data in the pipeline. // If there is, just shortcut the setup and continue to read the data as normal. - if (checkForOK(200,IPD_SEARCH, true)) { + if (checkForOK(200,F("+IPD"), true)) { DIAG(F("\nPreconfigured Wifi already running with data waiting\n")); - // loopstate=4; // carry on from correct place... or not as the case may be return WIFI_CONNECTED; } @@ -191,8 +188,8 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, // typical connect time approx 7 seconds delay(8000); 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)) + if (checkForOK(5000, F("+CIFSR:STAIP"), true,false)) + if (!checkForOK(1000, F("0.0.0.0"), true,false)) ipOK = true; } } else { @@ -215,8 +212,8 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, // Let's check for IP (via DHCP) ipOK = false; 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)) + if (checkForOK(5000, F("+CIFSR:STAIP"), true,false)) + if (!checkForOK(1000, F("0.0.0.0"), true,false)) ipOK = true; } } @@ -239,7 +236,7 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, // Figure out MAC addr StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); // not TOMATO // looking fpr mac addr eg +CIFSR:APMAC,"be:dd:c2:5c:6b:b7" - if (checkForOK(5000, (const char*) F("+CIFSR:APMAC,\""), true,false)) { + if (checkForOK(5000, F("+CIFSR:APMAC,\""), true,false)) { // Copy 17 byte mac address for (int i=0; i<17;i++) { while(!wifiStream->available()); @@ -257,10 +254,12 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, do { if (strncmp_P(yourNetwork, (const char*)password, 13) == 0) { // unconfigured - StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"PASS_%s\",1,4\r\n"), oldCmd ? "" : "_CUR", macTail, macTail); + StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"PASS_%s\",%d,4\r\n"), + oldCmd ? "" : "_CUR", macTail, macTail, channel); } else { // password configured by user - StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"%S\",1,4\r\n"), oldCmd ? "" : "_CUR", macTail, password); + StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"%S\",%d,4\r\n"), oldCmd ? "" : "_CUR", + macTail, password, channel); } } while (!checkForOK(WIFI_CONNECT_TIMEOUT, OK_SEARCH, true) && i++<2); // do twice if necessary but ignore failure as AP mode may still be ok if (i >= 2) @@ -283,7 +282,7 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, #endif //DONT_TOUCH_WIFI_CONF StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); // Display ip addresses to the DIAG - if (!checkForOK(1000, (const char *)F("IP,\"") , true, false)) return WIFI_DISCONNECTED; + if (!checkForOK(1000, F("IP,\"") , true, false)) return WIFI_DISCONNECTED; // Copy the IP address { const byte MAX_IP_LENGTH=15; @@ -331,9 +330,9 @@ void WifiInterface::ATCommand(const byte * command) { -bool WifiInterface::checkForOK( const unsigned int timeout, const char * waitfor, bool echo, bool escapeEcho) { +bool WifiInterface::checkForOK( const unsigned int timeout, const FSH * waitfor, bool echo, bool escapeEcho) { unsigned long startTime = millis(); - char const *locator = waitfor; + char *locator = (char *)waitfor; DIAG(F("\nWifi Check: [%E]"), waitfor); while ( millis() - startTime < timeout) { while (wifiStream->available()) { @@ -342,7 +341,7 @@ bool WifiInterface::checkForOK( const unsigned int timeout, const char * waitfor if (escapeEcho) StringFormatter::printEscape( ch); /// THIS IS A DIAG IN DISGUISE else DIAG(F("%c"), ch); } - if (ch != GETFLASH(locator)) locator = waitfor; + if (ch != GETFLASH(locator)) locator = (char *)waitfor; if (ch == GETFLASH(locator)) { locator++; if (!GETFLASH(locator)) { diff --git a/WifiInterface.h b/WifiInterface.h index 4070e75..8bf37e4 100644 --- a/WifiInterface.h +++ b/WifiInterface.h @@ -34,23 +34,19 @@ public: const FSH *wifiESSID, const FSH *wifiPassword, const FSH *hostname, - const int port = 2560); + const int port, + const byte channel); static void loop(); static void ATCommand(const byte *command); private: static wifiSerialState setup(Stream &setupStream, const FSH *SSSid, const FSH *password, - const FSH *hostname, int port); + const FSH *hostname, int port, byte channel); static Stream *wifiStream; static DCCEXParser parser; static wifiSerialState setup2(const FSH *SSSid, const FSH *password, - const FSH *hostname, int port); - static bool checkForOK(const unsigned int timeout, const char *waitfor, bool echo, bool escapeEcho = true); + const FSH *hostname, int port, byte channel); + static bool checkForOK(const unsigned int timeout, const FSH *waitfor, bool echo, bool escapeEcho = true); static bool connected; - static bool closeAfter; - static byte loopstate; - static int datalength; - static int connectionId; - static unsigned long loopTimeoutStart; }; #endif diff --git a/config.example.h b/config.example.h index 8c25ab9..e2dd822 100644 --- a/config.example.h +++ b/config.example.h @@ -72,6 +72,9 @@ The configuration file for DCC-EX Command Station // WIFI_HOSTNAME: You probably don't need to change this #define WIFI_HOSTNAME "dccex" // +// WIFI_CHANNEL: +#define WIFI_CHANNEL 1 +// ///////////////////////////////////////////////////////////////////////////////////// // // Wifi connect timeout in milliseconds. Default is 14000 (14 seconds). You only need diff --git a/defines.h b/defines.h index 6db42e1..478667e 100644 --- a/defines.h +++ b/defines.h @@ -21,10 +21,13 @@ //////////////////////////////////////////////////////////////////////////////// // // WIFI_ON: All prereqs for running with WIFI are met -// +// Note: WIFI_CHANNEL may not exist in early config.h files so is added here if needed. #if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO)) #define WIFI_ON true +#ifndef WIFI_CHANNEL +#define WIFI_CHANNEL 1 +#endif #else #define WIFI_ON false #endif From cae30f5faf903bc480154c587f9a556bf148d2cb Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sun, 14 Feb 2021 13:10:20 +0000 Subject: [PATCH 06/10] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 0461db2..a6c9b80 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "7d72624" +#define GITHUB_SHA "919b975" From 5a9d5d1f960579fc6cce5e05d8823b52bf6f3b96 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sun, 14 Feb 2021 20:20:36 +0000 Subject: [PATCH 07/10] Reduce duplicated F() macros Compiler isn't as clever as one might expect --- WifiInterface.cpp | 47 ++++++++++++++++++++++++++--------------------- WifiInterface.h | 3 ++- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 467b181..5d04400 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -26,7 +26,8 @@ #include "WifiInboundHandler.h" -#define OK_SEARCH F("\r\nOK\r\n") + + const unsigned long LOOP_TIMEOUT = 2000; bool WifiInterface::connected = false; @@ -125,7 +126,7 @@ wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, con if (wifiState == WIFI_CONNECTED) { StringFormatter::send(wifiStream, F("ATE0\r\n")); // turn off the echo - checkForOK(200, OK_SEARCH, true); + checkForOK(200, true); } @@ -144,7 +145,7 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, bool oldCmd = false; char macAddress[17]; // mac address extraction - + // First check... Restarting the Arduino does not restart the ES. // There may alrerady be a connection with data in the pipeline. // If there is, just shortcut the setup and continue to read the data as normal. @@ -154,25 +155,25 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, } StringFormatter::send(wifiStream, F("AT\r\n")); // Is something here that understands AT? - if(!checkForOK(200, OK_SEARCH, true)) + if(!checkForOK(200, true)) return WIFI_NOAT; // No AT compatible WiFi module here StringFormatter::send(wifiStream, F("ATE1\r\n")); // Turn on the echo, se we can see what's happening - checkForOK(2000, OK_SEARCH, true); // Makes this visible on the console + checkForOK(2000, true); // Makes this visible on the console // Display the AT version information StringFormatter::send(wifiStream, F("AT+GMR\r\n")); - checkForOK(2000, OK_SEARCH, true, false); // Makes this visible on the console + checkForOK(2000, true, false); // Makes this visible on the console #ifdef DONT_TOUCH_WIFI_CONF DIAG(F("\nDONT_TOUCH_WIFI_CONF was set: Using existing config\n")); #else StringFormatter::send(wifiStream, F("AT+CWMODE=1\r\n")); // configure as "station" = WiFi client - checkForOK(1000, OK_SEARCH, true); // Not always OK, sometimes "no change" + checkForOK(1000, true); // Not always OK, sometimes "no change" // Older ES versions have AT+CWJAP, newer ones have AT+CWJAP_CUR and AT+CWHOSTNAME StringFormatter::send(wifiStream, F("AT+CWJAP?\r\n")); - if (checkForOK(2000, OK_SEARCH, true)) { + if (checkForOK(2000, true)) { oldCmd=true; while (wifiStream->available()) StringFormatter::printEscape( wifiStream->read()); /// THIS IS A DIAG IN DISGUISE } @@ -197,14 +198,14 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, if (oldCmd) { // AT command early version supports CWJAP/CWSAP StringFormatter::send(wifiStream, F("AT+CWJAP=\"%S\",\"%S\"\r\n"), SSid, password); - ipOK = checkForOK(WIFI_CONNECT_TIMEOUT, OK_SEARCH, true); + ipOK = checkForOK(WIFI_CONNECT_TIMEOUT, true); } else { // later version supports CWJAP_CUR StringFormatter::send(wifiStream, F("AT+CWHOSTNAME=\"%S\"\r\n"), hostname); // Set Host name for Wifi Client - checkForOK(2000, OK_SEARCH, true); // dont care if not supported + checkForOK(2000, true); // dont care if not supported StringFormatter::send(wifiStream, F("AT+CWJAP_CUR=\"%S\",\"%S\"\r\n"), SSid, password); - ipOK = checkForOK(WIFI_CONNECT_TIMEOUT, OK_SEARCH, true); + ipOK = checkForOK(WIFI_CONNECT_TIMEOUT, true); } if (ipOK) { @@ -222,14 +223,14 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, // If we have not managed to get this going in station mode, go for AP mode // StringFormatter::send(wifiStream, F("AT+RST\r\n")); -// checkForOK(1000, OK_SEARCH, true); // Not always OK, sometimes "no change" +// checkForOK(1000, true); // Not always OK, sometimes "no change" int i=0; do { // configure as AccessPoint. Try really hard as this is the // last way out to get any Wifi connectivity. StringFormatter::send(wifiStream, F("AT+CWMODE=2\r\n")); - } while (!checkForOK(1000+i*500, OK_SEARCH, true) && i++<10); + } while (!checkForOK(1000+i*500, true) && i++<10); while (wifiStream->available()) StringFormatter::printEscape( wifiStream->read()); /// THIS IS A DIAG IN DISGUISE @@ -248,7 +249,7 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, } char macTail[]={macAddress[9],macAddress[10],macAddress[12],macAddress[13],macAddress[15],macAddress[16],'\0'}; - checkForOK(1000, OK_SEARCH, true, false); // suck up remainder of AT+CIFSR + checkForOK(1000, true, false); // suck up remainder of AT+CIFSR i=0; do { @@ -261,24 +262,24 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"%S\",%d,4\r\n"), oldCmd ? "" : "_CUR", macTail, password, channel); } - } while (!checkForOK(WIFI_CONNECT_TIMEOUT, OK_SEARCH, true) && i++<2); // do twice if necessary but ignore failure as AP mode may still be ok + } while (!checkForOK(WIFI_CONNECT_TIMEOUT, true) && i++<2); // do twice if necessary but ignore failure as AP mode may still be ok if (i >= 2) DIAG(F("\nWarning: Setting AP SSID and password failed\n")); // but issue warning if (!oldCmd) { StringFormatter::send(wifiStream, F("AT+CIPRECVMODE=0\r\n"), port); // make sure transfer mode is correct - checkForOK(2000, OK_SEARCH, true); + checkForOK(2000, true); } } StringFormatter::send(wifiStream, F("AT+CIPSERVER=0\r\n")); // turn off tcp server (to clean connections before CIPMUX=1) - checkForOK(1000, OK_SEARCH, true); // ignore result in case it already was off + checkForOK(1000, true); // ignore result in case it already was off StringFormatter::send(wifiStream, F("AT+CIPMUX=1\r\n")); // configure for multiple connections - if (!checkForOK(1000, OK_SEARCH, true)) return WIFI_DISCONNECTED; + if (!checkForOK(1000, true)) return WIFI_DISCONNECTED; StringFormatter::send(wifiStream, F("AT+CIPSERVER=1,%d\r\n"), port); // turn on server on port - if (!checkForOK(1000, OK_SEARCH, true)) return WIFI_DISCONNECTED; + if (!checkForOK(1000, true)) return WIFI_DISCONNECTED; #endif //DONT_TOUCH_WIFI_CONF StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); // Display ip addresses to the DIAG @@ -301,7 +302,7 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, LCD(4,F("%s"),ipString); // There is not enough room on some LCDs to put a title to this } // suck up anything after the IP. - if (!checkForOK(1000, OK_SEARCH, true, false)) return WIFI_DISCONNECTED; + if (!checkForOK(1000, true, false)) return WIFI_DISCONNECTED; LCD(5,F("PORT=%d\n"),port); return WIFI_CONNECTED; @@ -324,12 +325,16 @@ void WifiInterface::ATCommand(const byte * command) { } else { StringFormatter:: send(wifiStream, F("AT+%s\r\n"), command); - checkForOK(10000, OK_SEARCH, true); + checkForOK(10000, true); } } +bool WifiInterface::checkForOK( const unsigned int timeout, bool echo, bool escapeEcho) { + return checkForOK(timeout,F("\r\nOK\r\n"),echo,escapeEcho); +} + bool WifiInterface::checkForOK( const unsigned int timeout, const FSH * waitfor, bool echo, bool escapeEcho) { unsigned long startTime = millis(); char *locator = (char *)waitfor; diff --git a/WifiInterface.h b/WifiInterface.h index 8bf37e4..19f8a3a 100644 --- a/WifiInterface.h +++ b/WifiInterface.h @@ -38,7 +38,7 @@ public: const byte channel); static void loop(); static void ATCommand(const byte *command); - + private: static wifiSerialState setup(Stream &setupStream, const FSH *SSSid, const FSH *password, const FSH *hostname, int port, byte channel); @@ -46,6 +46,7 @@ private: static DCCEXParser parser; static wifiSerialState setup2(const FSH *SSSid, const FSH *password, const FSH *hostname, int port, byte channel); + static bool checkForOK(const unsigned int timeout, bool echo, bool escapeEcho = true); static bool checkForOK(const unsigned int timeout, const FSH *waitfor, bool echo, bool escapeEcho = true); static bool connected; }; From 8240a24193830798845d1cee62816a1a63341532 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sun, 14 Feb 2021 20:21:18 +0000 Subject: [PATCH 08/10] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index a6c9b80..8727263 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "919b975" +#define GITHUB_SHA "d4be9a8" From 0228345ca46555b87b87ac05a3dc600c51d687f7 Mon Sep 17 00:00:00 2001 From: Fred Date: Sun, 14 Feb 2021 18:19:41 -0500 Subject: [PATCH 09/10] Update config.example.h Add comment to wifi channel section --- config.example.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.example.h b/config.example.h index e2dd822..4105f64 100644 --- a/config.example.h +++ b/config.example.h @@ -72,7 +72,10 @@ The configuration file for DCC-EX Command Station // WIFI_HOSTNAME: You probably don't need to change this #define WIFI_HOSTNAME "dccex" // -// WIFI_CHANNEL: +// WIFI_CHANNEL: If the line "#define ENABLE_WIFI true" is uncommented, +// WiFi will be enabled (Mega only). The default channel is set to "1" whether +// this line exists or not. If you need to use an alternate channel (we recommend +// using only 1,6, or 11) you may change it here. #define WIFI_CHANNEL 1 // ///////////////////////////////////////////////////////////////////////////////////// From 3cc2418c7bc4508330f8d8b18cb698da44461ea8 Mon Sep 17 00:00:00 2001 From: Fred Date: Sun, 14 Feb 2021 23:19:57 +0000 Subject: [PATCH 10/10] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 8727263..a22d209 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "d4be9a8" +#define GITHUB_SHA "0228345"