Skip to content

Commit c15a50a

Browse files
committed
catM1: add ping check
1 parent 5098de3 commit c15a50a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/CatM1ConnectionHandler.cpp

+10-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,23 @@ 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

96+
Serial.println(_check_internet_availability);
97+
9398
if(!_check_internet_availability){
9499
return NetworkConnectionState::CONNECTED;
95100
}
96101

97-
int ping_result = GSM.ping("time.arduino.cc");
102+
Debug.print(DBG_INFO, F("Sending PING to outer space..."));
103+
int const ping_result = GSM.ping("time.arduino.cc");
98104
Debug.print(DBG_INFO, F("GSM.ping(): %d"), ping_result);
99105
if (ping_result < 0)
100106
{
101107
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)]);
108+
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), 2 * CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
103109
return NetworkConnectionState::CONNECTING;
104110
}
105111
else
@@ -114,6 +120,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnected()
114120
int const is_gsm_access_alive = GSM.isConnected();
115121
if (is_gsm_access_alive != 1)
116122
{
123+
Debug.print(DBG_ERROR, F("GSM connection not alive... disconnecting"));
117124
return NetworkConnectionState::DISCONNECTED;
118125
}
119126
return NetworkConnectionState::CONNECTED;

0 commit comments

Comments
 (0)