2020
2121#ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */
2222#include " EthernetConnectionHandler.h"
23+ #include < Udp.h>
2324
2425/* *****************************************************************************
2526 CTOR/DTOR
@@ -72,11 +73,6 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit()
7273 Debug.print (DBG_ERROR , F (" Error, ethernet shield was not found." ));
7374 return NetworkConnectionState::ERROR ;
7475 }
75- return NetworkConnectionState::CONNECTING ;
76- }
77-
78- NetworkConnectionState EthernetConnectionHandler::update_handleConnecting ()
79- {
8076 IPAddress ip (_settings.eth .ip .type , _settings.eth .ip .bytes );
8177
8278 // An ip address is provided -> static ip configuration
@@ -91,7 +87,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
9187 Debug.print (DBG_ERROR , F (" Failed to configure Ethernet, check cable connection" ));
9288 Debug.print (DBG_VERBOSE , " timeout: %d, response timeout: %d" ,
9389 _settings.eth .timeout , _settings.eth .response_timeout );
94- return NetworkConnectionState::CONNECTING ;
90+ return NetworkConnectionState::INIT ;
9591 }
9692 // An ip address is not provided -> dhcp configuration
9793 } else {
@@ -100,11 +96,33 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
10096 Debug.print (DBG_VERBOSE , " timeout: %d, response timeout: %d" ,
10197 _settings.eth .timeout , _settings.eth .response_timeout );
10298
103- return NetworkConnectionState::CONNECTING ;
99+ return NetworkConnectionState::INIT ;
104100 }
105101 }
106102
107- return NetworkConnectionState::CONNECTED ;
103+ return NetworkConnectionState::CONNECTING ;
104+ }
105+
106+ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting ()
107+ {
108+ if (Ethernet.linkStatus () == LinkOFF) {
109+ return NetworkConnectionState::INIT ;
110+ }
111+
112+ int ping_result = Ethernet.ping (" time.arduino.cc" );
113+ Debug.print (DBG_INFO , F (" Ethernet.ping(): %d" ), ping_result);
114+ if (ping_result < 0 )
115+ {
116+ Debug.print (DBG_ERROR , F (" Internet check failed" ));
117+ Debug.print (DBG_INFO , F (" Retrying in \" %d\" milliseconds" ), CHECK_INTERVAL_TABLE [static_cast <unsigned int >(NetworkConnectionState::CONNECTING )]);
118+ return NetworkConnectionState::CONNECTING ;
119+ }
120+ else
121+ {
122+ Debug.print (DBG_INFO , F (" Connected to Internet" ));
123+ return NetworkConnectionState::CONNECTED ;
124+ }
125+
108126}
109127
110128NetworkConnectionState EthernetConnectionHandler::update_handleConnected ()
0 commit comments