@@ -36,46 +36,61 @@ EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive)
36
36
37
37
NetworkConnectionState EthernetConnectionHandler::update_handleInit ()
38
38
{
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
52
43
return NetworkConnectionState::ERROR;
53
44
}
54
-
55
45
return NetworkConnectionState::CONNECTING;
56
46
}
57
47
58
48
NetworkConnectionState EthernetConnectionHandler::update_handleConnecting ()
59
49
{
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
+ }
60
56
return NetworkConnectionState::CONNECTED;
61
57
}
62
58
63
59
NetworkConnectionState EthernetConnectionHandler::update_handleConnected ()
64
60
{
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
+ }
68
72
return NetworkConnectionState::DISCONNECTED;
73
+ }
74
+ return NetworkConnectionState::CONNECTED;
69
75
}
70
76
71
77
NetworkConnectionState EthernetConnectionHandler::update_handleDisconnecting ()
72
78
{
79
+ Ethernet.disconnect ();
73
80
return NetworkConnectionState::DISCONNECTED;
74
81
}
75
82
76
83
NetworkConnectionState EthernetConnectionHandler::update_handleDisconnected ()
77
84
{
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
+ }
79
94
}
80
95
81
96
#endif /* #ifdef BOARD_HAS_ETHERNET */
0 commit comments