@@ -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 ){
@@ -187,11 +187,16 @@ bool ArduinoCellular::isConnectedToOperator(){
187187 return modem.isNetworkConnected ();
188188}
189189
190- bool ArduinoCellular::connectToGPRS (const char * apn, const char * gprsUser, const char * gprsPass){
190+ bool ArduinoCellular::connectToGPRS (const char * apn, const char * gprsUser, const char * gprsPass, bool waitForever ){
191191 if (this ->debugStream != nullptr ){
192192 this ->debugStream ->println (" Connecting to 4G network..." );
193193 }
194194 while (!modem.gprsConnect (apn, gprsUser, gprsPass)) {
195+
196+ if (!waitForever) {
197+ return false ;
198+ }
199+
195200 if (this ->debugStream != nullptr ){
196201 this ->debugStream ->print (" ." );
197202 }
@@ -243,7 +248,7 @@ bool ArduinoCellular::awaitNetworkRegistration(bool waitForever){
243248 this ->debugStream ->println (" Waiting for network registration..." );
244249 }
245250 while (!modem.waitForNetwork (waitForNetworkTimeout)) {
246-
251+
247252 if (!waitForever) {
248253 return false ;
249254 }
0 commit comments