1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-25 00:56:13 +01:00

Compare commits

..

No commits in common. "b44bebc1c6bb3320077982b3e7bd3c7d22ecf581" and "7ce1618a9c3b57bb0693f0e6817551b550c284b4" have entirely different histories.

8 changed files with 39 additions and 63 deletions

View File

@ -30,7 +30,6 @@
* © 2021 Neil McKechnie * © 2021 Neil McKechnie
* © 2020-2021 Chris Harlow, Harald Barth, David Cutting, * © 2020-2021 Chris Harlow, Harald Barth, David Cutting,
* Fred Decker, Gregor Baues, Anthony W - Dayton * Fred Decker, Gregor Baues, Anthony W - Dayton
* © 2023 Nathan Kellenicki
* All rights reserved. * All rights reserved.
* *
* This file is part of CommandStation-EX * This file is part of CommandStation-EX
@ -96,11 +95,11 @@ void setup()
// Start Ethernet if it exists // Start Ethernet if it exists
#ifndef ARDUINO_ARCH_ESP32 #ifndef ARDUINO_ARCH_ESP32
#if WIFI_ON #if WIFI_ON
WifiInterface::setup(WIFI_SERIAL_LINK_SPEED, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME), IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP); WifiInterface::setup(WIFI_SERIAL_LINK_SPEED, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME), IP_PORT, WIFI_CHANNEL);
#endif // WIFI_ON #endif // WIFI_ON
#else #else
// ESP32 needs wifi on always // ESP32 needs wifi on always
WifiESP::setup(WIFI_SSID, WIFI_PASSWORD, WIFI_HOSTNAME, IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP); WifiESP::setup(WIFI_SSID, WIFI_PASSWORD, WIFI_HOSTNAME, IP_PORT, WIFI_CHANNEL);
#endif // ARDUINO_ARCH_ESP32 #endif // ARDUINO_ARCH_ESP32
#if ETHERNET_ON #if ETHERNET_ON

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202307080654Z" #define GITHUB_SHA "devel-overcurrent-202307061457Z"

View File

@ -1,7 +1,6 @@
/* /*
© 2023 Paul M. Antoine © 2023, Paul M. Antoine
© 2021 Harald Barth © 2021, Harald Barth.
© 2023 Nathan Kellenicki
This file is part of CommandStation-EX This file is part of CommandStation-EX
@ -118,8 +117,7 @@ bool WifiESP::setup(const char *SSid,
const char *password, const char *password,
const char *hostname, const char *hostname,
int port, int port,
const byte channel, const byte channel) {
const bool forceAP) {
bool havePassword = true; bool havePassword = true;
bool haveSSID = true; bool haveSSID = true;
bool wifiUp = false; bool wifiUp = false;
@ -147,7 +145,7 @@ bool WifiESP::setup(const char *SSid,
if (strncmp(yourNetwork, password, 13) == 0 || strncmp("", password, 13) == 0) if (strncmp(yourNetwork, password, 13) == 0 || strncmp("", password, 13) == 0)
havePassword = false; havePassword = false;
if (haveSSID && havePassword && !forceAP) { if (haveSSID && havePassword) {
WiFi.setHostname(hostname); // Strangely does not work unless we do it HERE! WiFi.setHostname(hostname); // Strangely does not work unless we do it HERE!
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
#ifdef SERIAL_BT_COMMANDS #ifdef SERIAL_BT_COMMANDS
@ -185,11 +183,10 @@ bool WifiESP::setup(const char *SSid,
} }
} }
} }
if (!haveSSID || forceAP) { if (!haveSSID) {
// prepare all strings // prepare all strings
String strSSID(forceAP ? SSid : "DCCEX_"); String strSSID("DCCEX_");
String strPass(forceAP ? password : "PASS_"); String strPass("PASS_");
if (!forceAP) {
String strMac = WiFi.macAddress(); String strMac = WiFi.macAddress();
strMac.remove(0,9); strMac.remove(0,9);
strMac.replace(":",""); strMac.replace(":","");
@ -198,7 +195,6 @@ bool WifiESP::setup(const char *SSid,
std::transform(strMac.begin(), strMac.end(), strMac.begin(), asciitolower); std::transform(strMac.begin(), strMac.end(), strMac.begin(), asciitolower);
strSSID.concat(strMac); strSSID.concat(strMac);
strPass.concat(strMac); strPass.concat(strMac);
}
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
#ifdef SERIAL_BT_COMMANDS #ifdef SERIAL_BT_COMMANDS

View File

@ -1,6 +1,5 @@
/* /*
* © 2021 Harald Barth * © 2021, Harald Barth.
* © 2023 Nathan Kellenicki
* *
* This file is part of CommandStation-EX * This file is part of CommandStation-EX
* *
@ -32,8 +31,7 @@ public:
const char *wifiPassword, const char *wifiPassword,
const char *hostname, const char *hostname,
const int port, const int port,
const byte channel, const byte channel);
const bool forceAP);
static void loop(); static void loop();
private: private:
}; };

View File

@ -2,7 +2,6 @@
* © 2021 Fred Decker * © 2021 Fred Decker
* © 2020-2022 Harald Barth * © 2020-2022 Harald Barth
* © 2020-2022 Chris Harlow * © 2020-2022 Chris Harlow
* © 2023 Nathan Kellenicki
* All rights reserved. * All rights reserved.
* *
* This file is part of CommandStation-EX * This file is part of CommandStation-EX
@ -84,8 +83,7 @@ bool WifiInterface::setup(long serial_link_speed,
const FSH *wifiPassword, const FSH *wifiPassword,
const FSH *hostname, const FSH *hostname,
const int port, const int port,
const byte channel, const byte channel) {
const bool forceAP) {
wifiSerialState wifiUp = WIFI_NOAT; wifiSerialState wifiUp = WIFI_NOAT;
@ -97,13 +95,12 @@ bool WifiInterface::setup(long serial_link_speed,
(void) hostname; (void) hostname;
(void) port; (void) port;
(void) channel; (void) channel;
(void) forceAP;
#endif #endif
// See if the WiFi is attached to the first serial port // See if the WiFi is attached to the first serial port
#if NUM_SERIAL > 0 && !defined(SERIAL1_COMMANDS) #if NUM_SERIAL > 0 && !defined(SERIAL1_COMMANDS)
SERIAL1.begin(serial_link_speed); SERIAL1.begin(serial_link_speed);
wifiUp = setup(SERIAL1, wifiESSID, wifiPassword, hostname, port, channel, forceAP); wifiUp = setup(SERIAL1, wifiESSID, wifiPassword, hostname, port, channel);
#endif #endif
// Other serials are tried, depending on hardware. // Other serials are tried, depending on hardware.
@ -113,7 +110,7 @@ bool WifiInterface::setup(long serial_link_speed,
if (wifiUp == WIFI_NOAT) if (wifiUp == WIFI_NOAT)
{ {
Serial2.begin(serial_link_speed); Serial2.begin(serial_link_speed);
wifiUp = setup(Serial2, wifiESSID, wifiPassword, hostname, port, channel, forceAP); wifiUp = setup(Serial2, wifiESSID, wifiPassword, hostname, port, channel);
} }
#endif #endif
#endif #endif
@ -124,7 +121,7 @@ bool WifiInterface::setup(long serial_link_speed,
if (wifiUp == WIFI_NOAT) if (wifiUp == WIFI_NOAT)
{ {
SERIAL3.begin(serial_link_speed); SERIAL3.begin(serial_link_speed);
wifiUp = setup(SERIAL3, wifiESSID, wifiPassword, hostname, port, channel, forceAP); wifiUp = setup(SERIAL3, wifiESSID, wifiPassword, hostname, port, channel);
} }
#endif #endif
@ -142,7 +139,7 @@ bool WifiInterface::setup(long serial_link_speed,
} }
wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, const FSH* password, wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, const FSH* password,
const FSH* hostname, int port, byte channel, bool forceAP) { const FSH* hostname, int port, byte channel) {
wifiSerialState wifiState; wifiSerialState wifiState;
static uint8_t ntry = 0; static uint8_t ntry = 0;
ntry++; ntry++;
@ -151,7 +148,7 @@ wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, con
DIAG(F("++ Wifi Setup Try %d ++"), ntry); DIAG(F("++ Wifi Setup Try %d ++"), ntry);
wifiState = setup2( SSid, password, hostname, port, channel, forceAP); wifiState = setup2( SSid, password, hostname, port, channel);
if (wifiState == WIFI_NOAT) { if (wifiState == WIFI_NOAT) {
LCD(4, F("WiFi no AT chip")); LCD(4, F("WiFi no AT chip"));
@ -175,7 +172,7 @@ wifiSerialState WifiInterface::setup(Stream & setupStream, const FSH* SSid, con
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
#endif #endif
wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password,
const FSH* hostname, int port, byte channel, bool forceAP) { const FSH* hostname, int port, byte channel) {
bool ipOK = false; bool ipOK = false;
bool oldCmd = false; bool oldCmd = false;
@ -228,7 +225,7 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password,
if (!checkForOK(1000, F("0.0.0.0"), true,false)) if (!checkForOK(1000, F("0.0.0.0"), true,false))
ipOK = true; ipOK = true;
} }
} else if (!forceAP) { } else {
// SSID was configured, so we assume station (client) mode. // SSID was configured, so we assume station (client) mode.
if (oldCmd) { if (oldCmd) {
// AT command early version supports CWJAP/CWSAP // AT command early version supports CWJAP/CWSAP
@ -288,7 +285,6 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password,
i=0; i=0;
do { do {
if (!forceAP) {
if (STRNCMP_P(yourNetwork, (const char*)password, 13) == 0) { if (STRNCMP_P(yourNetwork, (const char*)password, 13) == 0) {
// unconfigured // unconfigured
StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"PASS_%s\",%d,4\r\n"), StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"PASS_%s\",%d,4\r\n"),
@ -298,10 +294,6 @@ 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", StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"%S\",%d,4\r\n"), oldCmd ? "" : "_CUR",
macTail, password, channel); macTail, password, channel);
} }
} else {
StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"%S\",\"%S\",%d,4\r\n"),
oldCmd ? "" : "_CUR", SSid, password, channel);
}
} while (!checkForOK(WIFI_CONNECT_TIMEOUT, 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) if (i >= 2)
DIAG(F("Warning: Setting AP SSID and password failed")); // but issue warning DIAG(F("Warning: Setting AP SSID and password failed")); // but issue warning

View File

@ -1,7 +1,6 @@
/* /*
* © 2020-2021 Chris Harlow * © 2020-2021 Chris Harlow
* © 2020, Harald Barth. * © 2020, Harald Barth.
* © 2023 Nathan Kellenicki
* All rights reserved. * All rights reserved.
* *
* This file is part of CommandStation-EX * This file is part of CommandStation-EX
@ -37,18 +36,17 @@ public:
const FSH *wifiPassword, const FSH *wifiPassword,
const FSH *hostname, const FSH *hostname,
const int port, const int port,
const byte channel, const byte channel);
const bool forceAP);
static void loop(); static void loop();
static void ATCommand(HardwareSerial * stream,const byte *command); static void ATCommand(HardwareSerial * stream,const byte *command);
private: private:
static wifiSerialState setup(Stream &setupStream, const FSH *SSSid, const FSH *password, static wifiSerialState setup(Stream &setupStream, const FSH *SSSid, const FSH *password,
const FSH *hostname, int port, byte channel, bool forceAP); const FSH *hostname, int port, byte channel);
static Stream *wifiStream; static Stream *wifiStream;
static DCCEXParser parser; static DCCEXParser parser;
static wifiSerialState setup2(const FSH *SSSid, const FSH *password, static wifiSerialState setup2(const FSH *SSSid, const FSH *password,
const FSH *hostname, int port, byte channel, bool forceAP); 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, bool echo, bool escapeEcho = true);
static bool checkForOK(const unsigned int timeout, const FSH *waitfor, bool echo, bool escapeEcho = true); static bool checkForOK(const unsigned int timeout, const FSH *waitfor, bool echo, bool escapeEcho = true);
static bool connected; static bool connected;

View File

@ -4,7 +4,6 @@
* © 2020-2023 Harald Barth * © 2020-2023 Harald Barth
* © 2020-2021 Fred Decker * © 2020-2021 Fred Decker
* © 2020-2021 Chris Harlow * © 2020-2021 Chris Harlow
* © 2023 Nathan Kellenicki
* *
* This file is part of CommandStation-EX * This file is part of CommandStation-EX
* *
@ -124,11 +123,6 @@ The configuration file for DCC-EX Command Station
// this line exists or not. If you need to use an alternate channel (we recommend // 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. // using only 1,6, or 11) you may change it here.
#define WIFI_CHANNEL 1 #define WIFI_CHANNEL 1
//
// WIFI_FORCE_AP: If you'd like to specify your own WIFI_SSID in AP mode, set this
// true. Otherwise it is assumed that you'd like to connect to an existing network
// with that SSID.
#define WIFI_FORCE_AP false
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //

View File

@ -3,8 +3,7 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "4.2.64" #define VERSION "4.2.63"
// 4.2.64 - new config WIFI_FORCE_AP option
// 4.2.63 - completely new overcurrent detection // 4.2.63 - completely new overcurrent detection
// - ESP32 protect from race in RMT code // - ESP32 protect from race in RMT code
// 4.2.62 - Update IO_RotaryEncoder.h to ignore sending current position // 4.2.62 - Update IO_RotaryEncoder.h to ignore sending current position