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

Using Serial2 and startup changes

This commit is contained in:
Harald Barth 2020-07-25 14:46:29 +02:00
parent 34dde6fe12
commit ed332efd2e
2 changed files with 22 additions and 10 deletions

View File

@ -92,8 +92,8 @@ void setup() {
// setup(serial, F(router name), F(password) , port) // setup(serial, F(router name), F(password) , port)
// //
#ifdef WIFI #ifdef WIFI
Serial1.begin(115200); Serial2.begin(115200);
WifiInterface::setup(Serial1, F("BTHub5-M6PT"), F("49de8d4862"),F("DCCEX"),F("CVReader"),3532); // (3532 is 0xDCC decimal... ) WifiInterface::setup(Serial2, F("BTHub5-M6PT"), F("49de8d4862"),F("DCCEX"),F("CVReader"),3532); // (3532 is 0xDCC decimal... )
#endif #endif
// This is just for demonstration purposes // This is just for demonstration purposes
@ -121,7 +121,7 @@ void loop() {
// Responsibility 3: Optionally handle any incoming WiFi traffic // Responsibility 3: Optionally handle any incoming WiFi traffic
#ifdef WIFI #ifdef WIFI
WifiInterface::loop(Serial1); WifiInterface::loop(Serial2);
#endif #endif
// Your additional code // Your additional code

View File

@ -23,6 +23,7 @@
#include "WiThrottle.h" #include "WiThrottle.h"
#include "HTTPParser.h" #include "HTTPParser.h"
const char PROGMEM READY_SEARCH[] ="\r\nready\r\n"; 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 OK_SEARCH[] ="\r\nOK\r\n";
const char PROGMEM END_DETAIL_SEARCH[] ="@ 1000"; const char PROGMEM END_DETAIL_SEARCH[] ="@ 1000";
const char PROGMEM PROMPT_SEARCH[] =">"; const char PROGMEM PROMPT_SEARCH[] =">";
@ -56,17 +57,25 @@ 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,END_DETAIL_SEARCH,true); // Show startup but ignore unreadable upto ready
checkForOK(wifiStream,5000,READY_SEARCH,true); checkForOK(wifiStream,5000,READY_SEARCH,true);
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"
StringFormatter::send(wifiStream, F("AT+CWHOSTNAME=\"%S\"\r\n"), hostname); // Set Host name for Wifi Client // StringFormatter::send(wifiStream, F("AT+CWHOSTNAME=\"%S\"\r\n"), hostname); // Set Host name for Wifi Client
checkForOK(wifiStream,2000, OK_SEARCH, true); // checkForOK(wifiStream,2000, OK_SEARCH, true);
// Older ES versions have AT+CWJAP, newer ones have AT+CWJAP_CUR and AT+CWHOSTNAME // 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); // 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);
if (!checkForOK(wifiStream,20000,OK_SEARCH,true)) { if (!checkForOK(wifiStream,20000,OK_SEARCH,true)) {
StringFormatter::send(wifiStream,F("AT+CWJAP_CUR=\"%S\",\"%S\"\r\n"),SSid,password); StringFormatter::send(wifiStream,F("AT+CWJAP_CUR?\r\n"),SSid,password);
if (!checkForOK(wifiStream,20000,OK_SEARCH,true)) return false; if (!checkForOK(wifiStream,20000,OK_SEARCH,true)) return false;
} }
@ -80,6 +89,9 @@ 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 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; 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 // 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; // if (!checkForOK(wifiStream,5000, OK_SEARCH, true)) return false;
(void)servername; // not currently in use (void)servername; // not currently in use