1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-11 21:31:02 +01:00

conditional WiFi setup

This commit is contained in:
Harald Barth 2020-07-31 12:46:57 +02:00
parent 4fce31158f
commit b0a7933b7b

View File

@ -50,6 +50,7 @@ void WifiInterface::setup(Stream & wifiStream, const __FlashStringHelper* SSid,
bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password, bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password,
const __FlashStringHelper* hostname, const __FlashStringHelper* servername, int port) { const __FlashStringHelper* hostname, const __FlashStringHelper* servername, int port) {
int ipOK=0;
delay(1000); delay(1000);
StringFormatter::send(wifiStream,F("AT+RST\r\n")); // reset module StringFormatter::send(wifiStream,F("AT+RST\r\n")); // reset module
@ -58,6 +59,14 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid,
StringFormatter::send(wifiStream,F("AT+GMR\r\n")); // request AT version StringFormatter::send(wifiStream,F("AT+GMR\r\n")); // request AT version
checkForOK(wifiStream,2000,OK_SEARCH,true); // Makes this visible on the console checkForOK(wifiStream,2000,OK_SEARCH,true); // Makes this visible on the console
StringFormatter::send(wifiStream,F("AT+CWMODE=1\r\n")); // configure as client
checkForOK(wifiStream,1000,OK_SEARCH,true); // Not always OK, sometimes "no change"
StringFormatter::send(wifiStream,F("AT+CIFSR\r\n"));
if(checkForOK(wifiStream,5000, (const char*) F("+CIFSR:STAIP"),true))
if(!checkForOK(wifiStream,1000, (const char*) F("0.0.0.0"),true))
ipOK=1;
if(!ipOK) {
StringFormatter::send(wifiStream,F("AT+CWMODE=3\r\n")); // configure as server or access point 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" checkForOK(wifiStream,1000,OK_SEARCH,true); // Not always OK, sometimes "no change"
@ -87,6 +96,7 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid,
StringFormatter::send(wifiStream,F("AT+CIFSR\r\n")); // get ip address //192.168.4.1 StringFormatter::send(wifiStream,F("AT+CIFSR\r\n")); // get ip address //192.168.4.1
if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false;
}
StringFormatter::send(wifiStream,F("AT+CIPMUX=1\r\n")); // configure for multiple connections StringFormatter::send(wifiStream,F("AT+CIPMUX=1\r\n")); // configure for multiple connections