From ad09360a54d8953615c7288abb85c737e1c2c342 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Sun, 28 Jan 2024 13:31:43 +0900 Subject: [PATCH] MDNS Generic library integration --- EthernetInterface.cpp | 12 ++++++++++++ EthernetInterface.h | 2 +- platformio.ini | 3 +++ version.h | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/EthernetInterface.cpp b/EthernetInterface.cpp index 8b1a643..b39d5af 100644 --- a/EthernetInterface.cpp +++ b/EthernetInterface.cpp @@ -29,6 +29,10 @@ #include "CommandDistributor.h" #include "WiThrottle.h" #include "DCCTimer.h" +#include "MDNS_Generic.h" + +EthernetUDP udp; +MDNS mdns(udp); EthernetInterface * EthernetInterface::singleton=NULL; /** @@ -175,6 +179,8 @@ bool EthernetInterface::checkLink() { server->begin(); LCD(4,F("IP: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); LCD(5,F("Port:%d"), IP_PORT); + mdns.begin(Ethernet.localIP(), "dccex"); // hostname + mdns.addServiceRecord("dccex._withrottle", 2560, MDNSServiceTCP); // only create a outboundRing it none exists, this may happen if the cable // gets disconnected and connected again if(!outboundRing) @@ -242,7 +248,11 @@ void EthernetInterface::loop2() { if (!clients[socket].connected()) { // stop any clients which disconnect CommandDistributor::forget(socket); clients[socket].stop(); + #if defined(ARDUINO_ARCH_AVR) clients[socket]=NULL; + #else + clients[socket]=(EthernetClient)nullptr; + #endif //if (Diag::ETHERNET) DIAG(F("Ethernet: disconnect %d "), socket); return; // Trick: So that we do not continue in this loop with client that is NULL @@ -262,6 +272,8 @@ void EthernetInterface::loop2() { } } + mdns.run(); + WiThrottle::loop(outboundRing); // handle at most 1 outbound transmission diff --git a/EthernetInterface.h b/EthernetInterface.h index f4f18dd..31780f4 100644 --- a/EthernetInterface.h +++ b/EthernetInterface.h @@ -46,7 +46,7 @@ #define MAX_SOCK_NUM 10 #else #include "Ethernet.h" - #define MAX_SOCK_NUM 4 +// #define MAX_SOCK_NUM 4 #endif #include "RingStream.h" diff --git a/platformio.ini b/platformio.ini index 93804de..898cda9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -103,6 +103,7 @@ framework = arduino lib_deps = ${env.lib_deps} arduino-libraries/Ethernet + MDNS_Generic SPI monitor_speed = 115200 monitor_echo = yes @@ -251,6 +252,7 @@ framework = arduino lib_deps = ${env.lib_deps} stm32duino/STM32Ethernet @ ^1.3.0 stm32duino/STM32duino LwIP @ ^2.1.2 + MDNS_Generic build_flags = -std=c++17 -Os -g2 -Wunused-variable monitor_speed = 115200 monitor_echo = yes @@ -266,6 +268,7 @@ framework = arduino lib_deps = ${env.lib_deps} stm32duino/STM32Ethernet @ ^1.3.0 stm32duino/STM32duino LwIP @ ^2.1.2 + MDNS_Generic build_flags = -std=c++17 -Os -g2 -Wunused-variable monitor_speed = 115200 monitor_echo = yes diff --git a/version.h b/version.h index 276f2a9..76de326 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.2.27stm32ECvf" +#define VERSION "5.2.27stm32ECvfmdns" +// 5.2.XX - MDNS Generic library integration for Ethernet // 5.2.XX - Variable frequency for DC mode // 5.2.27 - Bugfix: IOExpander memory allocation // 5.2.26 - Silently ignore overridden HAL defaults