Skip to content

Commit 36aa008

Browse files
committed
Add support for custom Ethernet timeouts
1 parent 1c5fb9b commit 36aa008

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/Arduino_EthernetConnectionHandler.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,38 @@
2424
CTOR/DTOR
2525
******************************************************************************/
2626

27-
EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive)
27+
EthernetConnectionHandler::EthernetConnectionHandler(unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
2828
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
2929
,_ip{INADDR_NONE}
3030
,_dns{INADDR_NONE}
3131
,_gateway{INADDR_NONE}
3232
,_netmask{INADDR_NONE}
33+
,_timeout{timeout}
34+
,_response_timeout{responseTimeout}
3335
{
3436

3537
}
3638

37-
EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive)
39+
EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
3840
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
3941
,_ip{ip}
4042
,_dns{dns}
4143
,_gateway{gateway}
4244
,_netmask{netmask}
45+
,_timeout{timeout}
46+
,_response_timeout{responseTimeout}
4347
{
4448

4549
}
4650

47-
EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive)
51+
EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive)
4852
: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
4953
,_ip{INADDR_NONE}
5054
,_dns{INADDR_NONE}
5155
,_gateway{INADDR_NONE}
5256
,_netmask{INADDR_NONE}
57+
,_timeout{timeout}
58+
,_response_timeout{responseTimeout}
5359
{
5460
if(!_ip.fromString(ip)) {
5561
_ip = INADDR_NONE;
@@ -81,13 +87,15 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit()
8187
NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
8288
{
8389
if (_ip != INADDR_NONE) {
84-
if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, 15000, 4000) == 0) {
90+
if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, _timeout, _response_timeout) == 0) {
8591
Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection"));
92+
Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout);
8693
return NetworkConnectionState::CONNECTING;
8794
}
8895
} else {
89-
if (Ethernet.begin(nullptr, 15000, 4000) == 0) {
96+
if (Ethernet.begin(nullptr, _timeout, _response_timeout) == 0) {
9097
Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection"));
98+
Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout);
9199
return NetworkConnectionState::CONNECTING;
92100
}
93101
}

src/Arduino_EthernetConnectionHandler.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class EthernetConnectionHandler : public ConnectionHandler
3131
{
3232
public:
3333

34-
EthernetConnectionHandler(bool const keep_alive = true);
35-
EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive = true);
36-
EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive = true);
34+
EthernetConnectionHandler(unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true);
35+
EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true);
36+
EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true);
3737

3838

3939
virtual unsigned long getTime() override { return 0; }
@@ -56,6 +56,9 @@ class EthernetConnectionHandler : public ConnectionHandler
5656
IPAddress _gateway;
5757
IPAddress _netmask;
5858

59+
unsigned long _timeout;
60+
unsigned long _response_timeout;
61+
5962
EthernetUDP _eth_udp;
6063
EthernetClient _eth_client;
6164

0 commit comments

Comments
 (0)