Skip to content

Commit b2d33d6

Browse files
committed
Clean up examples
1 parent e6b7ba2 commit b2d33d6

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

examples/HTTPClient/HTTPClient.ino

+22-9
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ const int port = 80;
1010
ArduinoCellular cellular = ArduinoCellular();
1111
HttpClient client = cellular.getHTTPClient(server, port);
1212

13-
void setup(){
14-
Serial.begin(115200);
15-
while (!Serial);
16-
cellular.begin();
17-
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
18-
}
19-
20-
void loop(){
13+
void getResource(){
2114

2215
Serial.println("Making GET request...");
2316

@@ -32,7 +25,27 @@ void loop(){
3225
Serial.println(response);
3326

3427
client.stop();
28+
}
3529

36-
delay(5000);
30+
void setup(){
31+
Serial.begin(115200);
32+
while (!Serial);
33+
// cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
34+
cellular.begin();
3735

36+
if(String(SECRET_PINNUMBER).length() > 0 && !cellular.unlockSIM(SECRET_PINNUMBER)){
37+
Serial.println("Failed to unlock SIM card.");
38+
while(true); // Stop here
39+
}
40+
41+
Serial.println("Connecting...");
42+
if(!cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD)){
43+
Serial.println("Failed to connect to the network.");
44+
while(true); // Stop here
45+
}
46+
Serial.println("Connected!");
47+
48+
getResource();
3849
}
50+
51+
void loop(){}

examples/HTTPSClient/HTTPSClient.ino

+25-10
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@ const int port = 443;
1111
ArduinoCellular cellular = ArduinoCellular();
1212
HttpClient client = cellular.getHTTPSClient(server, port);
1313

14-
void setup(){
15-
Serial.begin(115200);
16-
while (!Serial);
17-
18-
cellular.begin();
19-
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
20-
}
21-
22-
void loop(){
14+
void getResource(){
2315
Serial.println("Making GET request...");
2416

2517
client.get(resource);
@@ -33,5 +25,28 @@ void loop(){
3325
Serial.println(response);
3426

3527
client.stop();
36-
delay(5000);
3728
}
29+
30+
void setup(){
31+
Serial.begin(115200);
32+
while (!Serial);
33+
34+
// cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
35+
cellular.begin();
36+
37+
if(String(SECRET_PINNUMBER).length() > 0 && !cellular.unlockSIM(SECRET_PINNUMBER)){
38+
Serial.println("Failed to unlock SIM card.");
39+
while(true); // Stop here
40+
}
41+
42+
Serial.println("Connecting...");
43+
if(!cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD)){
44+
Serial.println("Failed to connect to the network.");
45+
while(true); // Stop here
46+
}
47+
Serial.println("Connected!");
48+
49+
getResource();
50+
}
51+
52+
void loop(){}

examples/ReceiveSMS/ReceiveSMS.ino

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ void setup(){
2525
while (!Serial);
2626
// cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
2727
cellular.begin();
28+
29+
String pinCode = ""; // If your SIM card has a PIN code, specify it here e.g. "1234"
30+
if(pinCode.length() > 0 && !cellular.unlockSIM(pinCode)){
31+
Serial.println("Failed to unlock SIM card.");
32+
while(true); // Stop here
33+
}
2834

29-
Serial.println("Connecting...");
35+
Serial.println("Connecting to network...");
3036
cellular.connect();
3137
Serial.println("Connected!");
3238

examples/SendSMS/SendSMS.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ void setup(){
2222
while (!Serial);
2323
delay(1000); // Give the serial monitor some time to start
2424

25+
// cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
2526
cellular.begin();
26-
String pinCode = "1234"; // If your SIM card has a PIN code, specify it here
2727

28+
String pinCode = ""; // If your SIM card has a PIN code, specify it here e.g. "1234"
2829
if(pinCode.length() > 0 && !cellular.unlockSIM(pinCode)){
2930
Serial.println("Failed to unlock SIM card.");
3031
while(true); // Stop here
3132
}
3233

3334
Serial.println("Connecting to network...");
3435
cellular.connect(); // APN settings are not required for sending SMS
36+
Serial.println("Connected!");
3537

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

0 commit comments

Comments
 (0)