@@ -63,25 +63,46 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit()
63
63
pinMode (ON_MKR2, OUTPUT);
64
64
digitalWrite (ON_MKR2, HIGH);
65
65
#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
+ }
66
72
return NetworkConnectionState::CONNECTING;
67
73
}
68
74
69
75
NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting ()
70
76
{
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 )
72
79
{
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 " ));
74
81
return NetworkConnectionState::DISCONNECTED;
75
82
}
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
+ }
78
98
}
79
99
80
100
NetworkConnectionState CatM1ConnectionHandler::update_handleConnected ()
81
101
{
82
102
int const is_gsm_access_alive = GSM.isConnected ();
83
103
if (is_gsm_access_alive != 1 )
84
104
{
105
+ Debug.print (DBG_ERROR, F (" GSM connection not alive... disconnecting" ));
85
106
return NetworkConnectionState::DISCONNECTED;
86
107
}
87
108
return NetworkConnectionState::CONNECTED;
0 commit comments