@@ -63,25 +63,46 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit()
6363 pinMode (ON_MKR2, OUTPUT);
6464 digitalWrite (ON_MKR2, HIGH);
6565#endif
66+
67+ if (!GSM.begin (_pin, _apn, _login, _pass, _rat, _band))
68+ {
69+ Debug.print (DBG_ERROR, F (" The board was not able to register to the network..." ));
70+ return NetworkConnectionState::DISCONNECTED;
71+ }
6672 return NetworkConnectionState::CONNECTING;
6773}
6874
6975NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting ()
7076{
71- if (!GSM.begin (_pin, _apn, _login, _pass, _rat, _band))
77+ int const is_gsm_access_alive = GSM.isConnected ();
78+ if (is_gsm_access_alive != 1 )
7279 {
73- Debug.print (DBG_ERROR, F (" The board was not able to register to the network ..." ));
80+ Debug.print (DBG_ERROR, F (" GSM connection not alive ... disconnecting " ));
7481 return NetworkConnectionState::DISCONNECTED;
7582 }
76- Debug.print (DBG_INFO, F (" Connected to Network" ));
77- return NetworkConnectionState::CONNECTED;
83+
84+ Debug.print (DBG_INFO, F (" Sending PING to outer space..." ));
85+ int const ping_result = GSM.ping (" time.arduino.cc" );
86+ Debug.print (DBG_INFO, F (" GSM.ping(): %d" ), ping_result);
87+ if (ping_result < 0 )
88+ {
89+ Debug.print (DBG_ERROR, F (" PING failed" ));
90+ Debug.print (DBG_INFO, F (" Retrying in \" %d\" milliseconds" ), 2 * CHECK_INTERVAL_TABLE[static_cast <unsigned int >(NetworkConnectionState::CONNECTING)]);
91+ return NetworkConnectionState::CONNECTING;
92+ }
93+ else
94+ {
95+ Debug.print (DBG_INFO, F (" Connected to Network" ));
96+ return NetworkConnectionState::CONNECTED;
97+ }
7898}
7999
80100NetworkConnectionState CatM1ConnectionHandler::update_handleConnected ()
81101{
82102 int const is_gsm_access_alive = GSM.isConnected ();
83103 if (is_gsm_access_alive != 1 )
84104 {
105+ Debug.print (DBG_ERROR, F (" GSM connection not alive... disconnecting" ));
85106 return NetworkConnectionState::DISCONNECTED;
86107 }
87108 return NetworkConnectionState::CONNECTED;
0 commit comments