Skip to content

Commit

Permalink
Fix Ethernet cable disconnect message
Browse files Browse the repository at this point in the history
  • Loading branch information
pmantoine committed Feb 1, 2024
1 parent ad09360 commit d1f558d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
36 changes: 23 additions & 13 deletions EthernetInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
* © 2024 Morten "Doc" Nielsen
* © 2023-2024 Paul M. Antoine
* © 2022 Bruno Sanches
* © 2021 Fred Decker
* © 2020-2022 Harald Barth
Expand Down Expand Up @@ -174,31 +176,39 @@ bool EthernetInterface::checkLink() {
Ethernet.setLocalIP(myIP); // for static IP, set it again
#endif
#endif
IPAddress ip = Ethernet.localIP(); // look what IP was obtained (dynamic or static)
server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT
server->begin();
IPAddress ip = Ethernet.localIP(); // look what IP was obtained (dynamic or static)
if (ip[0] == 0)
LCD(4,F("Awaiting DHCP..."));
while (ip[0] == 0) { // wait until we are given an IP address from the DHCP server
// LCD(4,F("."));
ip = Ethernet.localIP(); // look what IP was obtained (dynamic or static)
}
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)
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
}
return true;
} else { // connected
DIAG(F("Ethernet cable disconnected"));
connected=false;
//clean up any client
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++) {
if(clients[socket].connected())
clients[socket].stop();
} else { // LinkOFF
if (connected) {
DIAG(F("Ethernet cable disconnected"));
connected=false;
//clean up any client
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++) {
if(clients[socket].connected())
clients[socket].stop();
}
// tear down server
delete server;
server = nullptr;
LCD(4,F("IP: None"));
}
// tear down server
delete server;
server = nullptr;
LCD(4,F("IP: None"));
}
return false;
}
Expand Down
1 change: 1 addition & 0 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "StringFormatter.h"

#define VERSION "5.2.27stm32ECvfmdns"
// 5.2.XX - Fix Ethernet cable disconnected message, wait for DHCP
// 5.2.XX - MDNS Generic library integration for Ethernet
// 5.2.XX - Variable frequency for DC mode
// 5.2.27 - Bugfix: IOExpander memory allocation
Expand Down

0 comments on commit d1f558d

Please sign in to comment.