@@ -43,33 +43,46 @@ void ArduinoCellular::begin() {
4343
4444}
4545
46- bool ArduinoCellular::connect (String apn, String gprsUser , String gprsPass , String pin){
46+ bool ArduinoCellular::connect (String apn, String username , String password , String pin){
4747 SimStatus simStatus = getSimStatus ();
4848 if (simStatus == SimStatus::SIM_LOCKED && pin.length () > 0 ){
4949 unlockSIM (pin.c_str ());
5050 }
5151
5252 simStatus = getSimStatus ();
53- if (simStatus == SimStatus::SIM_READY) {
54- if (awaitNetworkRegistration ()){
55- if (connectToGPRS (apn.c_str (), gprsUser.c_str (), gprsPass.c_str ())){
56- if (this ->debugStream != nullptr ){
57- this ->debugStream ->println (" Setting DNS..." );
58- }
59-
60- auto response = this ->sendATCommand (" +QIDNSCFG=1,\" 8.8.8.8\" ,\" 8.8.4.4\" " );
61-
62- if (this ->debugStream != nullptr ){
63- this ->debugStream ->println (response);
64- }
65- return true ;
66- }
53+ if (simStatus != SimStatus::SIM_READY) {
54+ if (this ->debugStream != nullptr ){
55+ this ->debugStream ->println (" SIM not ready or incorrect PIN provided." );
56+ }
57+ return false ;
58+ }
59+
60+ if (!awaitNetworkRegistration ()){
61+ return false ;
62+ }
63+
64+ if (apn.length () == 0 ){
65+ if (this ->debugStream != nullptr ){
66+ this ->debugStream ->println (" No APN specified, not connecting to GPRS" );
67+ }
68+ return true ;
69+ }
70+
71+ if (connectToGPRS (apn.c_str (), username.c_str (), password.c_str ())){
72+ auto response = this ->sendATCommand (" +QIDNSCFG=1,\" 8.8.8.8\" ,\" 8.8.4.4\" " );
73+
74+ if (response.indexOf (" OK" ) != -1 ){
75+ return true ;
6776 } else {
77+ if (this ->debugStream != nullptr ){
78+ this ->debugStream ->println (" Failed to set DNS." );
79+ }
6880 return false ;
6981 }
82+
7083 }
7184
72- return false ;
85+ return false ;
7386}
7487
7588
0 commit comments