mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-07-28 09:53:45 +02:00
Alter Stream to Print
In prep for Wifi siolution, all output functions changed to expect Print class instead of Stream... Can still pass Serial1 etc because Stream extends Print, but this allows for an output-only class extending Print to collect a response buffer for Wifi sending with AT commands.
This commit is contained in:
@@ -1,49 +1,49 @@
|
||||
//
|
||||
//#include "WifiInterface.h"
|
||||
//#include "Config.h"
|
||||
//#include "DIAG.h"
|
||||
//
|
||||
//
|
||||
//WiFiEspServer WifiInterface::server(WIFI_PORT);
|
||||
//
|
||||
//bool WifiInterface::connected=false;
|
||||
//
|
||||
//void WifiInterface::setup()
|
||||
//{
|
||||
// Serial1.begin(WIFI_BAUD_RATE); // initialize serial for ESP module
|
||||
// WiFi.init(&Serial1); // initialize ESP module
|
||||
//
|
||||
// // check for the presence of the shield
|
||||
// if (WiFi.status() == WL_NO_SHIELD) {
|
||||
// Serial.println("WiFi shield not present");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // attempt to connect to WiFi network
|
||||
// int status = WL_IDLE_STATUS;
|
||||
// for (int retries=0;status != WL_CONNECTED && retries<WIFI_CONNECT_RETRIES; retries++) {
|
||||
// DIAG(F("\nAttempting to connect to WPA SSID: %s\n"),WIFI_SSID);
|
||||
// delay(100);
|
||||
// status = WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
// }
|
||||
//
|
||||
// if (status==WL_CONNECTED) {
|
||||
// connected=true;
|
||||
//
|
||||
//
|
||||
// // start the web server on port WIFI_PORT
|
||||
// server.begin();
|
||||
//
|
||||
// // print the SSID of the network you're attached to
|
||||
// DIAG(F("SSID: %s IP=%s "), WiFi.SSID(), WiFi.localIP());
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void WifiInterface::loop(DCCEXParser * parser) {
|
||||
// if (!connected) return existing;
|
||||
// if (!client) return existing;
|
||||
// DIAG(F("\nnew Wifi Client connected %s \n"),client.remoteIP());
|
||||
// if (existing) delete existing;
|
||||
// return new DCCEXParser(client);
|
||||
//}
|
||||
#include "WifiInterface.h"
|
||||
#include "Config.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
|
||||
WiFiEspServer WifiInterface::server(WIFI_PORT);
|
||||
WiFiEspClient WifiInterface::client;
|
||||
bool WifiInterface::haveClient=false;
|
||||
bool WifiInterface::connected=false;
|
||||
|
||||
void WifiInterface::setup()
|
||||
{
|
||||
Serial1.begin(WIFI_BAUD_RATE); // initialize serial for ESP module
|
||||
WiFi.init(&Serial1); // initialize ESP module
|
||||
|
||||
// check for the presence of the shield
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
return;
|
||||
}
|
||||
|
||||
// attempt to connect to WiFi network
|
||||
int status = WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
if (status==WL_CONNECTED) {
|
||||
connected=true;
|
||||
|
||||
// start the server on port WIFI_PORT
|
||||
server.begin();
|
||||
|
||||
// print the SSID of the network you're attached to
|
||||
DIAG(F("\nWifi Connected SSID: %s IP=%d.%d.%d.%d port %d\n "),
|
||||
WiFi.SSID(), WiFi.localIP()[0],WiFi.localIP()[1],WiFi.localIP()[2],WiFi.localIP()[3],WIFI_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WifiInterface::loop(DCCEXParser & parser) {
|
||||
if (!connected) return;
|
||||
|
||||
WiFiEspClient xclient= server.available(); // listen for incoming clients
|
||||
if (xclient.connected()) {
|
||||
DIAG(F("\nNew Wifi Client connected\n"));
|
||||
parser.loop(xclient);
|
||||
xclient.stop();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user