1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-04-10 23:40:12 +02:00

WiFi UDP working as well

This commit is contained in:
Gregor Baues 2020-11-09 18:48:17 +01:00
parent 34fe1256e7
commit edc38169dc
5 changed files with 19 additions and 20 deletions

View File

@ -80,7 +80,7 @@ void setup()
// wifi.setup(WIFI, TCP, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME)); // wifi.setup(WIFI, TCP, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME));
// wifi.setup(WIFI, TCP, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME, 2323) // wifi.setup(WIFI, TCP, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME, 2323)
eth1.setup(ETHERNET, UDPR); // ETHERNET, UDP on Port 2560 eth1.setup(WIFI, UDPR); // ETHERNET, UDP on Port 2560
// eth1.setup(ETHERNET, TCP); // ETHERNET, UDP on Port 2560 // eth1.setup(ETHERNET, TCP); // ETHERNET, UDP on Port 2560
// eth2.setup(ETHERNET, TCP, 23); // ETHERNET, TCP on Port 23 for the CLI // eth2.setup(ETHERNET, TCP, 23); // ETHERNET, TCP on Port 23 for the CLI
// eth1.setup(ETHERNET, TCP, 8888); // ETHERNET, TCP on Port 8888 // eth1.setup(ETHERNET, TCP, 8888); // ETHERNET, TCP on Port 8888

View File

@ -104,8 +104,9 @@ byte EthernetSetup::setup()
dnsip = Ethernet.dnsServerIP(); dnsip = Ethernet.dnsServerIP();
INFO(F("DNS server IP address: [%d.%d.%d.%d] "), dnsip[0], dnsip[1], dnsip[2], dnsip[3]); INFO(F("DNS server IP address: [%d.%d.%d.%d] "), dnsip[0], dnsip[1], dnsip[2], dnsip[3]);
INFO(F("Number of connections: [%d]"), maxConnections); INFO(F("Number of connections: [%d]"), maxConnections);
return true;
} }
return connected; return false; // something went wrong
} }
EthernetSetup::EthernetSetup() {} EthernetSetup::EthernetSetup() {}

View File

@ -84,20 +84,22 @@ void NetworkInterface::setup(transportType transport, protocolType protocol, uin
case WIFI: case WIFI:
{ {
WifiSetup wSetup(port, protocol); WifiSetup wSetup(port, protocol);
ok = wSetup.setup(); if (wSetup.setup())
if (ok)
{ {
wifiTransport = new Transport<WiFiServer, WiFiClient, WiFiUDP>; wifiTransport = new Transport<WiFiServer, WiFiClient, WiFiUDP>;
wifiTransport->id = _dccNet.add(wifiTransport, transport); wifiTransport->id = _dccNet.add(wifiTransport, transport);
wifiTransport->server = wSetup.getServer(); wifiTransport->server = wSetup.getTCPServer();
wifiTransport->port = port; wifiTransport->port = port;
wifiTransport->protocol = protocol; wifiTransport->protocol = protocol;
wifiTransport->transport = transport; wifiTransport->transport = transport;
wifiTransport->udp = wSetup.getUDPServer(); // 0 if TCP is used
wifiTransport->maxConnections = wSetup.maxConnections; wifiTransport->maxConnections = wSetup.maxConnections;
ok = wifiTransport->setup(this); ok = wifiTransport->setup(this);
DBG(F("Interface [%x] bound to transport id [%d:%x]"), this, wifiTransport->id, wifiTransport); DBG(F("Interface [%x] bound to transport id [%d:%x]"), this, wifiTransport->id, wifiTransport);
break; } else {
}; ok = false;
}
break;
}; };
case ETHERNET: case ETHERNET:
{ {

View File

@ -46,23 +46,20 @@ bool WifiSetup::setup() {
{ {
case UDPR: case UDPR:
{ {
INFO(F("\nUDP over Wifi is not yet supported\n"));
connected = false; connected = false;
/*
udp = new WiFiUDP(); udp = new WiFiUDP();
byte udpState = udp->begin(port);
maxConnections = 1; if (udpState)
// DIAG(F("Wifi/UDP: [%x:%d]"), udp, port);
if (udp->begin(port)) // no need to call begin for the WiFiEspAT library but doesn't run properly in the context of the application
{ {
TRC(F("UDP status: %d"), udpState);
maxConnections = 1; // there is only one UDP object listening for incomming data
connected = true; connected = true;
} }
else else
{ {
DIAG(F("\nUDP client failed to start")); ERR(F("UDP failed to start"));
connected = false; connected = false;
} }
*/
break; break;
}; };
case TCP: case TCP:
@ -97,11 +94,9 @@ bool WifiSetup::setup() {
dnsip = WiFi.dnsServer1(); dnsip = WiFi.dnsServer1();
INFO(F("DNS server IP address: [%d.%d.%d.%d] "), dnsip[0], dnsip[1], dnsip[2], dnsip[3]); INFO(F("DNS server IP address: [%d.%d.%d.%d] "), dnsip[0], dnsip[1], dnsip[2], dnsip[3]);
INFO(F("Number of connections: [%d]"), maxConnections); INFO(F("Number of connections: [%d]"), maxConnections);
if( protocol == UDPR ) return 0; // no server here as we use UDP
return true; return true;
} }
// something went wrong return false; // something went wrong
return false;
}; };

View File

@ -42,10 +42,11 @@ public:
bool setup(); bool setup();
WiFiUDP* getUdp() { WiFiUDP* getUDPServer() {
return udp; return udp;
} }
WiFiServer* getServer() {
WiFiServer* getTCPServer() {
return server; return server;
} }