Skip to content

Commit 7c50a80

Browse files
committed
catM1: add ping check by default
1 parent c7ca8ee commit 7c50a80

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/CatM1ConnectionHandler.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ CatM1ConnectionHandler::CatM1ConnectionHandler(
3737
: ConnectionHandler{keep_alive, NetworkAdapter::CATM1}
3838
{
3939
_settings.type = NetworkAdapter::CATM1;
40+
// To keep the backward compatibility, the user can call enableCheckInternetAvailability(false) for disabling the check
41+
_check_internet_availability = true;
4042
strncpy(_settings.catm1.pin, pin, sizeof(_settings.catm1.pin)-1);
4143
strncpy(_settings.catm1.apn, apn, sizeof(_settings.catm1.apn)-1);
4244
strncpy(_settings.catm1.login, login, sizeof(_settings.catm1.login)-1);
@@ -87,19 +89,21 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting()
8789
{
8890
if (!GSM.isConnected())
8991
{
90-
return NetworkConnectionState::INIT;
92+
Debug.print(DBG_ERROR, F("GSM connection not alive... disconnecting"));
93+
return NetworkConnectionState::DISCONNECTED;
9194
}
9295

9396
if(!_check_internet_availability){
9497
return NetworkConnectionState::CONNECTED;
9598
}
9699

97-
int ping_result = GSM.ping("time.arduino.cc");
100+
Debug.print(DBG_INFO, F("Sending PING to outer space..."));
101+
int const ping_result = GSM.ping("time.arduino.cc");
98102
Debug.print(DBG_INFO, F("GSM.ping(): %d"), ping_result);
99103
if (ping_result < 0)
100104
{
101105
Debug.print(DBG_ERROR, F("Internet check failed"));
102-
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
106+
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), 2 * CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
103107
return NetworkConnectionState::CONNECTING;
104108
}
105109
else
@@ -114,6 +118,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnected()
114118
int const is_gsm_access_alive = GSM.isConnected();
115119
if (is_gsm_access_alive != 1)
116120
{
121+
Debug.print(DBG_ERROR, F("GSM connection not alive... disconnecting"));
117122
return NetworkConnectionState::DISCONNECTED;
118123
}
119124
return NetworkConnectionState::CONNECTED;

0 commit comments

Comments
 (0)