Skip to content

Commit b415e2f

Browse files
committed
Make SIM unlock explicit
1 parent 9c5325e commit b415e2f

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

examples/SendSMS/SendSMS.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
*/
1616
#include "ArduinoCellular.h"
1717

18-
const char apn[] = "internet";
19-
const char gprsUser[] = "";
20-
const char gprsPass[] = "";
21-
2218
ArduinoCellular cellular = ArduinoCellular();
2319

2420
void setup(){
@@ -29,8 +25,13 @@ void setup(){
2925
cellular.begin();
3026
String pinCode = "1234"; // If your SIM card has a PIN code, specify it here
3127

28+
if(pinCode.length() > 0 && !cellular.unlockSIM(pinCode)){
29+
Serial.println("Failed to unlock SIM card.");
30+
while(true); // Stop here
31+
}
32+
3233
Serial.println("Connecting to network...");
33-
cellular.connect(apn, gprsUser, gprsPass, pinCode);
34+
cellular.connect(); // APN settings are not required for sending SMS
3435

3536
Serial.println("Sending SMS...");
3637
cellular.sendSMS("<INSERT_NUMBER_HERE>", "bleep bleep");

src/ArduinoCellular.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ SimStatus ArduinoCellular::getSimStatus(){
202202
}
203203
}
204204

205-
bool ArduinoCellular::unlockSIM(const char * pin){
205+
bool ArduinoCellular::unlockSIM(String pin){
206206
if(this->debugStream != nullptr){
207207
this->debugStream->println("Unlocking SIM...");
208208
}
209-
return modem.simUnlock(pin);
209+
return modem.simUnlock(pin.c_str());
210210
}
211211

212212
bool ArduinoCellular::awaitNetworkRegistration(){

src/ArduinoCellular.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ class ArduinoCellular {
9494
*/
9595
void begin();
9696

97+
/**
98+
* @brief Unlocks the SIM card using the specified PIN.
99+
* @param pin The SIM card PIN.
100+
* @return True if the SIM card is unlocked, false otherwise.
101+
*/
102+
bool unlockSIM(String pin);
103+
97104
/**
98105
* @brief Registers with the cellular network and connects to the Internet
99106
* if the APN, GPRS username, and GPRS password are provided.
@@ -237,13 +244,6 @@ class ArduinoCellular {
237244
*/
238245
SimStatus getSimStatus();
239246

240-
/**
241-
* @brief Unlocks the SIM card using the specified PIN.
242-
* @param pin The SIM card PIN.
243-
* @return True if the SIM card is unlocked, false otherwise.
244-
*/
245-
bool unlockSIM(const char * pin);
246-
247247
/**
248248
* @brief Waits for network registration. (Blocking call)
249249
* @return True if the network registration is successful, false otherwise.

0 commit comments

Comments
 (0)