Closed bcsanches closed 1 year ago
This is a very good idea. I think it should look someting like this with signgleton->connected used like this:
In EthernetInterface::loop():
if(!singleton || (!singleton->checkLink()))
return;
and then checkLink like this:
bool EthernetInterface::checkLink() {
if (Ethernet.linkStatus() == LinkON) {
if (!connected) {
DIAG(F("Ethernet cable connected"));
connected=true;
IPAddress ip = Ethernet.localIP(); // reassign the obtained ip address
server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT
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);
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
}
return true;
} else {
if (connected) {
DIAG(F("Ethernet cable disconnected"));
connected=false;
/* tear down server */
LCD(4,F("IP: None"));
}
return false;
}
}
The tear down server part has to be written but that would allow to disconnect and reconnect cable. I think. We can try to make it possible ;-)
Cheers, Harald.
Thank you! I implemented those proposals. Now trying to figure out how to update the pull request.
Nice. I often find it is easier to make a new pull request and we throw away the old one. But I think we pull this in and if there are any problems let's deal with them later. I can not test with an ethernet shield anyway as I do not have one. Harald.
I did several tests here and seems to works ok. Connected and disconnected the cable several times. It appears to be stable. Thank you
I simplified the setup code and did reformat to our mostly used code style. See latest commit. Added your name to the (c) in EthernetInterface.cpp. Thanks again.
Looking nice! Thank you!
Instead of keeping a limited loop during Ethernet setup, I propose this change to keep checking the link status until it becomes stable and ethernet link is stable and ip is obtained.
This makes life easier for debugging and testing, also if for some reason the link takes longer to becomes stable, the initialization process will not kill the ehternet singleton.