Skip to content

Commit e853987

Browse files
committed
enable or disable check internet availability
1 parent 0ed8bb2 commit e853987

9 files changed

+34
-2
lines changed

Diff for: src/CatM1ConnectionHandler.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit()
7676
Debug.print(DBG_ERROR, F("The board was not able to register to the network..."));
7777
return NetworkConnectionState::ERROR;
7878
}
79-
80-
8179
return NetworkConnectionState::CONNECTING;
8280
}
8381

@@ -87,6 +85,11 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting()
8785
{
8886
return NetworkConnectionState::INIT;
8987
}
88+
89+
if(!_check_internet_availability){
90+
return NetworkConnectionState::CONNECTED;
91+
}
92+
9093
int ping_result = GSM.ping("time.arduino.cc");
9194
Debug.print(DBG_INFO, F("GSM.ping(): %d"), ping_result);
9295
if (ping_result < 0)

Diff for: src/CellularConnectionHandler.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ NetworkConnectionState CellularConnectionHandler::update_handleConnecting()
7777
return NetworkConnectionState::INIT;
7878
}
7979

80+
if (!_check_internet_availability) {
81+
return NetworkConnectionState::CONNECTED;
82+
}
83+
8084
if(getTime() == 0){
8185
Debug.print(DBG_ERROR, F("Internet check failed"));
8286
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);

Diff for: src/ConnectionHandlerInterface.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter inter
2929
: _keep_alive{keep_alive}
3030
, _interface{interface}
3131
, _lastConnectionTickTime{millis()}
32+
, _check_internet_availability{false}
3233
, _current_net_connection_state{NetworkConnectionState::INIT}
3334
{
3435

Diff for: src/ConnectionHandlerInterface.h

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class ConnectionHandler {
7676

7777
virtual void connect();
7878
virtual void disconnect();
79+
void enableCheckInternetAvailability(bool enable) {
80+
_check_internet_availability = enable;
81+
}
7982

8083
virtual void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback);
8184
void addConnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated));
@@ -106,6 +109,7 @@ class ConnectionHandler {
106109
virtual void updateCallback(NetworkConnectionState next_net_connection_state);
107110

108111
bool _keep_alive;
112+
bool _check_internet_availability;
109113
NetworkAdapter _interface;
110114

111115
virtual NetworkConnectionState update_handleInit () = 0;

Diff for: src/EthernetConnectionHandler.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
109109
return NetworkConnectionState::INIT;
110110
}
111111

112+
if (!_check_internet_availability) {
113+
return NetworkConnectionState::CONNECTED;
114+
}
115+
112116
int ping_result = Ethernet.ping("time.arduino.cc");
113117
Debug.print(DBG_INFO, F("Ethernet.ping(): %d"), ping_result);
114118
if (ping_result < 0)

Diff for: src/GSMConnectionHandler.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ GSMConnectionHandler::GSMConnectionHandler(const char * pin, const char * apn, c
5353
: ConnectionHandler{keep_alive, NetworkAdapter::GSM}
5454
{
5555
_settings.type = NetworkAdapter::GSM;
56+
// To keep the backward compatibility, the user can call enableCheckInternetAvailability(false) for disabling the check
57+
_check_internet_availability = true;
5658
strcpy(_settings.gsm.pin, pin);
5759
strcpy(_settings.gsm.apn, apn);
5860
strcpy(_settings.gsm.login, login);
@@ -105,6 +107,10 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit()
105107

106108
NetworkConnectionState GSMConnectionHandler::update_handleConnecting()
107109
{
110+
if(!_check_internet_availability){
111+
return NetworkConnectionState::CONNECTED;
112+
}
113+
108114
Debug.print(DBG_INFO, F("Sending PING to outer space..."));
109115
int const ping_result = _gprs.ping("time.arduino.cc");
110116
Debug.print(DBG_INFO, F("GPRS.ping(): %d"), ping_result);

Diff for: src/GenericConnectionHandler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ bool GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) {
4141
if(_ch != nullptr) {
4242
_interface = s.type;
4343
_ch->setKeepAlive(_keep_alive);
44+
_ch->enableCheckInternetAvailability(_check_internet_availability);
4445
return _ch->updateSetting(s);
4546
} else {
4647
_interface = NetworkAdapter::NONE;

Diff for: src/NBConnectionHandler.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ NetworkConnectionState NBConnectionHandler::update_handleConnecting()
123123
return NetworkConnectionState::INIT;
124124
}
125125

126+
if(!_check_internet_availability){
127+
return NetworkConnectionState::CONNECTED;
128+
}
129+
126130
int ping_result = _nb_gprs.ping("time.arduino.cc");
127131
Debug.print(DBG_INFO, F("GPRS.ping(): %d"), ping_result);
128132
if (ping_result < 0)

Diff for: src/WiFiConnectionHandler.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting()
135135
if (WiFi.status() != WL_CONNECTED){
136136
return NetworkConnectionState::INIT;
137137
}
138+
139+
if(!_check_internet_availability){
140+
return NetworkConnectionState::CONNECTED;
141+
}
142+
138143
#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32)
139144
int ping_result = WiFi.ping("time.arduino.cc");
140145
Debug.print(DBG_INFO, F("WiFi.ping(): %d"), ping_result);

0 commit comments

Comments
 (0)