mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
wifi setup tristate
This commit is contained in:
parent
59a1a8eb1b
commit
c6cff3b4bd
|
@ -57,7 +57,7 @@ bool WifiInterface::setup(long serial_link_speed,
|
|||
const __FlashStringHelper *hostname,
|
||||
const int port) {
|
||||
|
||||
bool wifiUp = false;
|
||||
wifiSerialState wifiUp = WIFI_NOAT;
|
||||
|
||||
#if NUM_SERIAL == 0
|
||||
// no warning about unused parameters.
|
||||
|
@ -75,7 +75,7 @@ bool WifiInterface::setup(long serial_link_speed,
|
|||
|
||||
// Other serials are tried, depending on hardware.
|
||||
#if NUM_SERIAL > 1
|
||||
if (!wifiUp)
|
||||
if (wifiUp == WIFI_NOAT)
|
||||
{
|
||||
Serial2.begin(serial_link_speed);
|
||||
wifiUp = setup(Serial2, wifiESSID, wifiPassword, hostname, port);
|
||||
|
@ -83,18 +83,22 @@ bool WifiInterface::setup(long serial_link_speed,
|
|||
#endif
|
||||
|
||||
#if NUM_SERIAL > 2
|
||||
if (!wifiUp)
|
||||
if (wifiUp == WIFI_NOAT)
|
||||
{
|
||||
Serial3.begin(serial_link_speed);
|
||||
wifiUp = setup(Serial3, wifiESSID, wifiPassword, hostname, port);
|
||||
}
|
||||
#endif
|
||||
|
||||
return wifiUp;
|
||||
if (wifiUp == WIFI_CONNECTED)
|
||||
connected = true;
|
||||
else
|
||||
connected = false;
|
||||
return connected;
|
||||
}
|
||||
|
||||
bool WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password,
|
||||
const __FlashStringHelper* hostname, int port) {
|
||||
wifiSerialState WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password,
|
||||
const __FlashStringHelper* hostname, int port) {
|
||||
wifiSerialState wifiState;
|
||||
static uint8_t ntry = 0;
|
||||
ntry++;
|
||||
|
||||
|
@ -102,9 +106,14 @@ bool WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid
|
|||
|
||||
DIAG(F("\n++ Wifi Setup Try %d ++\n"), ntry);
|
||||
|
||||
connected = setup2( SSid, password, hostname, port);
|
||||
wifiState = setup2( SSid, password, hostname, port);
|
||||
|
||||
if (connected) {
|
||||
if (wifiState == WIFI_NOAT) {
|
||||
DIAG(F("\n++ Wifi Setup NO AT ++\n"));
|
||||
return wifiState;
|
||||
}
|
||||
|
||||
if (wifiState == WIFI_CONNECTED) {
|
||||
StringFormatter::send(wifiStream, F("ATE0\r\n")); // turn off the echo
|
||||
checkForOK(200, OK_SEARCH, true);
|
||||
}
|
||||
|
@ -112,12 +121,12 @@ bool WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid
|
|||
DCCEXParser::setAtCommandCallback(ATCommand);
|
||||
WifiInboundHandler::setup(wifiStream);
|
||||
|
||||
DIAG(F("\n++ Wifi Setup %S ++\n"), connected ? F("OK") : F("FAILED"));
|
||||
return connected;
|
||||
DIAG(F("\n++ Wifi Setup %S ++\n"), wifiState == WIFI_CONNECTED ? F("CONNECTED") : F("DISCONNECTED"));
|
||||
return wifiState;
|
||||
}
|
||||
|
||||
bool WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringHelper* password,
|
||||
const __FlashStringHelper* hostname, int port) {
|
||||
wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringHelper* password,
|
||||
const __FlashStringHelper* hostname, int port) {
|
||||
bool ipOK = false;
|
||||
bool oldCmd = false;
|
||||
|
||||
|
@ -129,12 +138,12 @@ bool WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringH
|
|||
if (checkForOK(200,IPD_SEARCH, 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 true;
|
||||
return WIFI_CONNECTED;
|
||||
}
|
||||
|
||||
StringFormatter::send(wifiStream, F("AT\r\n")); // Is something here that understands AT?
|
||||
if(!checkForOK(200, OK_SEARCH, true))
|
||||
return false; // No AT compatible WiFi module here
|
||||
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
|
||||
|
@ -237,16 +246,16 @@ bool WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringH
|
|||
checkForOK(10000, 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 false;
|
||||
if (!checkForOK(10000, 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 false;
|
||||
if (!checkForOK(10000, OK_SEARCH, true)) return WIFI_DISCONNECTED;
|
||||
|
||||
StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); // Display ip addresses to the DIAG
|
||||
if (!checkForOK(10000, OK_SEARCH, true, false)) return false;
|
||||
if (!checkForOK(10000, OK_SEARCH, true, false)) return WIFI_DISCONNECTED;
|
||||
DIAG(F("\nPORT=%d\n"),port);
|
||||
|
||||
return true;
|
||||
return WIFI_CONNECTED;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <Arduino.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
enum wifiSerialState { WIFI_NOAT, WIFI_DISCONNECTED, WIFI_CONNECTED };
|
||||
|
||||
class WifiInterface
|
||||
{
|
||||
|
||||
|
@ -37,11 +39,11 @@ public:
|
|||
static void ATCommand(const byte *command);
|
||||
|
||||
private:
|
||||
static bool setup(Stream &setupStream, const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
||||
static wifiSerialState setup(Stream &setupStream, const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
||||
const __FlashStringHelper *hostname, int port);
|
||||
static Stream *wifiStream;
|
||||
static DCCEXParser parser;
|
||||
static bool setup2(const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
||||
static wifiSerialState setup2(const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
||||
const __FlashStringHelper *hostname, int port);
|
||||
static bool checkForOK(const unsigned int timeout, const char *waitfor, bool echo, bool escapeEcho = true);
|
||||
static bool connected;
|
||||
|
|
Loading…
Reference in New Issue
Block a user