diff --git a/CVReader.ino b/CVReader.ino index 39ef57d..1abe39c 100644 --- a/CVReader.ino +++ b/CVReader.ino @@ -92,8 +92,8 @@ void setup() { // setup(serial, F(router name), F(password) , port) // #ifdef WIFI - Serial2.begin(115200); - WifiInterface::setup(Serial2, F("BTHub5-M6PT"), F("49de8d4862"),F("DCCEX"),F("CVReader"),3532); // (3532 is 0xDCC decimal... ) + Serial1.begin(115200); + WifiInterface::setup(Serial1, F("BTHub5-M6PT"), F("49de8d4862"),F("DCCEX"),F("CVReader"),3532); // (3532 is 0xDCC decimal... ) #endif // This is just for demonstration purposes @@ -121,7 +121,7 @@ void loop() { // Responsibility 3: Optionally handle any incoming WiFi traffic #ifdef WIFI - WifiInterface::loop(Serial2); + WifiInterface::loop(Serial1); #endif // Your additional code diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 21963bc..34efe1b 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -23,7 +23,6 @@ #include "WiThrottle.h" #include "HTTPParser.h" const char PROGMEM READY_SEARCH[] ="\r\nready\r\n"; -const char PROGMEM WIFIOK_SEARCH[] ="\r\nWIFI GOT IPready\r\n"; const char PROGMEM OK_SEARCH[] ="\r\nOK\r\n"; const char PROGMEM END_DETAIL_SEARCH[] ="@ 1000"; const char PROGMEM PROMPT_SEARCH[] =">"; @@ -57,28 +56,20 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid, //checkForOK(wifiStream,5000,END_DETAIL_SEARCH,true); // Show startup but ignore unreadable upto ready checkForOK(wifiStream,5000,READY_SEARCH,true); -// 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+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); + 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; -// } - - checkForOK(wifiStream,5000,WIFIOK_SEARCH,true); - - StringFormatter::send(wifiStream,F("AT+CWJAP?\r\n"),SSid,password); + 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?\r\n"),SSid,password); + 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+CIFSR\r\n")); // get ip address //192.168.4.1 if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; @@ -89,9 +80,6 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid, StringFormatter::send(wifiStream,F("AT+CIPSERVER=1,%d\r\n"),port); // turn on server on port 80 if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; - StringFormatter::send(wifiStream,F("AT+CIPRECVMODE=0\r\n"),port); // turn on server on port 80 - 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