@@ -36,46 +36,61 @@ EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive)
3636
3737NetworkConnectionState EthernetConnectionHandler::update_handleInit ()
3838{
39- if (Ethernet.begin () == 0 ) {
40- Debug.print (DBG_ERROR, F (" Failed to configure Ethernet using DHCP" ));
41-
42- if (Ethernet.hardwareStatus () == EthernetNoHardware) {
43- Debug.print (DBG_ERROR, F (" Error, ethernet shield was not found." ));
44- return NetworkConnectionState::ERROR;
45- }
46-
47- if (Ethernet.linkStatus () == LinkOFF) {
48- Debug.print (DBG_ERROR, F (" Error, ethernet cable is not connected." ));
49- return NetworkConnectionState::ERROR;
50- }
51-
39+ if (Ethernet.hardwareStatus () == EthernetNoHardware) {
40+ #if !defined(__AVR__)
41+ Debug.print (DBG_ERROR, F (" Error, ethernet shield was not found." ));
42+ #endif
5243 return NetworkConnectionState::ERROR;
5344 }
54-
5545 return NetworkConnectionState::CONNECTING;
5646}
5747
5848NetworkConnectionState EthernetConnectionHandler::update_handleConnecting ()
5949{
50+ if (Ethernet.begin (nullptr , 15000 , 4000 ) == 0 ) {
51+ #if !defined(__AVR__)
52+ Debug.print (DBG_ERROR, F (" Waiting Ethernet configuration from DHCP server, check cable connection" ));
53+ #endif
54+ return NetworkConnectionState::CONNECTING;
55+ }
6056 return NetworkConnectionState::CONNECTED;
6157}
6258
6359NetworkConnectionState EthernetConnectionHandler::update_handleConnected ()
6460{
65- if (Ethernet.linkStatus () == LinkON)
66- return NetworkConnectionState::CONNECTED;
67- else
61+ if (Ethernet.linkStatus () == LinkOFF) {
62+ #if !defined(__AVR__)
63+ Debug.print (DBG_VERBOSE, F (" Ethernet.status(): %d" ), Ethernet.status ());
64+ Debug.print (DBG_ERROR, F (" Connection lost." ));
65+ #endif
66+ if (_keep_alive)
67+ {
68+ #if !defined(__AVR__)
69+ Debug.print (DBG_ERROR, F (" Attempting reconnection" ));
70+ #endif
71+ }
6872 return NetworkConnectionState::DISCONNECTED;
73+ }
74+ return NetworkConnectionState::CONNECTED;
6975}
7076
7177NetworkConnectionState EthernetConnectionHandler::update_handleDisconnecting ()
7278{
79+ Ethernet.disconnect ();
7380 return NetworkConnectionState::DISCONNECTED;
7481}
7582
7683NetworkConnectionState EthernetConnectionHandler::update_handleDisconnected ()
7784{
78- return NetworkConnectionState::INIT;
85+ Ethernet.end ();
86+ if (_keep_alive)
87+ {
88+ return NetworkConnectionState::INIT;
89+ }
90+ else
91+ {
92+ return NetworkConnectionState::CLOSED;
93+ }
7994}
8095
8196#endif /* #ifdef BOARD_HAS_ETHERNET */
0 commit comments