2626
2727EthernetConnectionHandler::EthernetConnectionHandler (bool const keep_alive)
2828: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
29+ ,_ip{INADDR_NONE}
30+ ,_dns{INADDR_NONE}
31+ ,_gateway{INADDR_NONE}
32+ ,_subnet{INADDR_NONE}
33+ {
34+
35+ }
36+
37+ EthernetConnectionHandler::EthernetConnectionHandler (IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, bool const keep_alive)
38+ : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET}
39+ ,_ip{ip}
40+ ,_dns{dns}
41+ ,_gateway{gateway}
42+ ,_subnet{subnet}
2943{
3044
3145}
@@ -47,11 +61,20 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit()
4761
4862NetworkConnectionState EthernetConnectionHandler::update_handleConnecting ()
4963{
50- if (Ethernet.begin (nullptr , 15000 , 4000 ) == 0 ) {
64+ if (_ip != INADDR_NONE) {
65+ if (Ethernet.begin (nullptr , _ip, _dns, _gateway, _subnet, 15000 , 4000 ) == 0 ) {
5166#if !defined(__AVR__)
52- Debug.print (DBG_ERROR, F (" Waiting Ethernet configuration from DHCP server , check cable connection" ));
67+ Debug.print (DBG_ERROR, F (" Failed to configure Ethernet , check cable connection" ));
5368#endif
54- return NetworkConnectionState::CONNECTING;
69+ return NetworkConnectionState::CONNECTING;
70+ }
71+ } else {
72+ if (Ethernet.begin (nullptr , 15000 , 4000 ) == 0 ) {
73+ #if !defined(__AVR__)
74+ Debug.print (DBG_ERROR, F (" Waiting Ethernet configuration from DHCP server, check cable connection" ));
75+ #endif
76+ return NetworkConnectionState::CONNECTING;
77+ }
5578 }
5679 return NetworkConnectionState::CONNECTED;
5780}
0 commit comments