1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 21:21:24 +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)
//
#ifdef WIFI
Serial1.begin(115200);
WifiInterface::setup(Serial1, F("BTHub5-M6PT"), F("49de8d4862"),F("DCCEX"),F("CVReader"),3532); // (3532 is 0xDCC decimal... )
Serial2.begin(115200);
WifiInterface::setup(Serial2, 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(Serial1);
WifiInterface::loop(Serial2);
#endif
// Your additional code

View File

@ -23,6 +23,7 @@
#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[] =">";
@ -56,20 +57,28 @@ 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);
// 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)) {
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;
}
StringFormatter::send(wifiStream,F("AT+CIFSR\r\n")); // get ip address //192.168.4.1
if (!checkForOK(wifiStream,10000,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
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