From 32b507248d9393e3d742f4bd02fcf0e6d2ef08bc Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 25 Jul 2020 15:16:06 +0100 Subject: [PATCH] Update WifiInterface.cpp Merge newer AT commands and freveal AT version at startup --- WifiInterface.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 34efe1b..460630a 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -53,22 +53,37 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid, delay(1000); StringFormatter::send(wifiStream,F("AT+RST\r\n")); // reset module - //checkForOK(wifiStream,5000,END_DETAIL_SEARCH,true); // Show startup but ignore unreadable upto ready - checkForOK(wifiStream,5000,READY_SEARCH,true); - + checkForOK(wifiStream,5000,READY_SEARCH,false); // generally not interesting to DCC + + StringFormatter::send(wifiStream,F("AT+GMR\r\n")); // request AT version + checkForOK(wifiStream,2000,OK_SEARCH,true); // Makes this visible on the console + StringFormatter::send(wifiStream,F("AT+CWMODE=3\r\n")); // configure as server or access point checkForOK(wifiStream,1000,OK_SEARCH,true); // Not always OK, sometimes "no change" - StringFormatter::send(wifiStream, F("AT+CWHOSTNAME=\"%S\"\r\n"), hostname); // Set Host name for Wifi Client - checkForOK(wifiStream,2000, OK_SEARCH, true); - - // Older ES versions have AT+CWJAP, newer ones have AT+CWJAP_CUR and AT+CWHOSTNAME - StringFormatter::send(wifiStream,F("AT+CWJAP=\"%S\",\"%S\"\r\n"),SSid,password); - if (!checkForOK(wifiStream,20000,OK_SEARCH,true)) { - StringFormatter::send(wifiStream,F("AT+CWJAP_CUR=\"%S\",\"%S\"\r\n"),SSid,password); - if (!checkForOK(wifiStream,20000,OK_SEARCH,true)) return false; + StringFormatter::send(wifiStream,F("AT+CWJAP?\r\n")); + if (checkForOK(wifiStream,2000,OK_SEARCH,true)) { + // early version supports CWJAP + StringFormatter::send(wifiStream,F("AT+CWJAP=\"%S\",\"%S\"\r\n"),SSid,password); + checkForOK(wifiStream,20000,OK_SEARCH,true); // can ignore failure as AP mode may still be ok } + else { + // later version supports CWJAP_CUR + StringFormatter::send(wifiStream, F("AT+CWHOSTNAME=\"%S\"\r\n"), hostname); // Set Host name for Wifi Client + checkForOK(wifiStream,2000, OK_SEARCH, true); // dont care if not supported + + StringFormatter::send(wifiStream,F("AT+CWJAP_CUR=\"%S\",\"%S\"\r\n"),SSid,password); + checkForOK(wifiStream,20000,OK_SEARCH,true); // can ignore failure as AP mode may still be ok + + StringFormatter::send(wifiStream,F("AT+CIPRECVMODE=0\r\n"),port); // make sure transfer mode is correct + checkForOK(wifiStream,2000,OK_SEARCH,true); + + // StringFormatter::send(wifiStream, F("AT+MDNS=1,\"%S.local\",\"%S.local\",%d\r\n"), hostname, servername, port); // Setup mDNS for Server + // if (!checkForOK(wifiStream,5000, OK_SEARCH, true)) return false; + (void)servername; // avoid compiler warning from commented out AT_MDNS above + + } StringFormatter::send(wifiStream,F("AT+CIFSR\r\n")); // get ip address //192.168.4.1 if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; @@ -77,12 +92,9 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid, StringFormatter::send(wifiStream,F("AT+CIPMUX=1\r\n")); // configure for multiple connections if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; - StringFormatter::send(wifiStream,F("AT+CIPSERVER=1,%d\r\n"),port); // turn on server on port 80 + StringFormatter::send(wifiStream,F("AT+CIPSERVER=1,%d\r\n"),port); // turn on server on port if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; - // StringFormatter::send(wifiStream, F("AT+MDNS=1,\"%S.local\",\"%S.local\",%d\r\n"), hostname, servername, port); // Setup mDNS for Server - // if (!checkForOK(wifiStream,5000, OK_SEARCH, true)) return false; - (void)servername; // not currently in use return true; }