@@ -78,7 +78,7 @@ bool ArduinoCellular::connect(String apn, String username, String password, bool
7878 return true ;
7979 }
8080
81- if (connectToGPRS (apn.c_str (), username.c_str (), password.c_str ())){
81+ if (connectToGPRS (apn.c_str (), username.c_str (), password.c_str (), waitForever )){
8282 auto response = this ->sendATCommand (" +QIDNSCFG=1,\" 8.8.8.8\" ,\" 8.8.4.4\" " );
8383
8484 if (response.indexOf (" OK" ) != -1 ){
@@ -196,11 +196,16 @@ bool ArduinoCellular::isConnectedToOperator(){
196196 return modem.isNetworkConnected ();
197197}
198198
199- bool ArduinoCellular::connectToGPRS (const char * apn, const char * gprsUser, const char * gprsPass){
199+ bool ArduinoCellular::connectToGPRS (const char * apn, const char * gprsUser, const char * gprsPass, bool waitForever ){
200200 if (this ->debugStream != nullptr ){
201201 this ->debugStream ->println (" Connecting to 4G network..." );
202202 }
203203 while (!modem.gprsConnect (apn, gprsUser, gprsPass)) {
204+
205+ if (!waitForever) {
206+ return false ;
207+ }
208+
204209 if (this ->debugStream != nullptr ){
205210 this ->debugStream ->print (" ." );
206211 }
@@ -252,7 +257,7 @@ bool ArduinoCellular::awaitNetworkRegistration(bool waitForever){
252257 this ->debugStream ->println (" Waiting for network registration..." );
253258 }
254259 while (!modem.waitForNetwork (waitForNetworkTimeout)) {
255-
260+
256261 if (!waitForever) {
257262 return false ;
258263 }
0 commit comments