Skip to content

Commit 9c5325e

Browse files
committed
Remove need to supply APN settings
1 parent 0b32193 commit 9c5325e

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

examples/ReceiveSMS/ReceiveSMS.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void setup(){
2929
cellular.begin();
3030

3131
Serial.println("Connecting...");
32-
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
32+
cellular.connect();
3333

3434
// Register interrupt based callback for new SMS
3535
attachInterrupt(digitalPinToInterrupt(NEW_SMS_INTERRUPT_PIN), onSMSReceived, RISING);

examples/ReceiveSMS/arduino_secrets.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/ArduinoCellular.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/ArduinoCellular.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ class ArduinoCellular {
9595
void begin();
9696

9797
/**
98-
* @brief Connects to the network using the specified APN, GPRS username, and GPRS password.
98+
* @brief Registers with the cellular network and connects to the Internet
99+
* if the APN, GPRS username, and GPRS password are provided.
99100
* @param apn The Access Point Name.
100-
* @param gprsUser The GPRS username.
101-
* @param gprsPass The GPRS password.
101+
* @param username The APN username.
102+
* @param password The APN password.
102103
* @param pin The SIM card PIN.
103104
* @return True if the connection is successful, false otherwise.
104105
*/
105-
bool connect(String apn, String gprsUser, String gprsPass, String pin = "");
106+
bool connect(String apn = "", String username = "", String password = "", String pin = "");
106107

107108
/**
108109
* @brief Checks if the modem is registered on the network.

0 commit comments

Comments
 (0)