Skip to content

Commit 7d99372

Browse files
Merge pull request #5 from arduino-libraries/examples-cleanup
Examples cleanup
2 parents fb90af3 + 7809283 commit 7d99372

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

examples/HTTPClient/HTTPClient.ino

+6-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
#include "ArduinoCellular.h"
44
#include "arduino_secrets.h"
55

6-
76
const char server[] = "vsh.pp.ua";
87
const char resource[] = "/TinyGSM/logo.txt";
98
const int port = 80;
109

1110
ArduinoCellular cellular = ArduinoCellular();
12-
HttpClient http = cellular.getHTTPClient(server, port);
13-
11+
HttpClient client = cellular.getHTTPClient(server, port);
1412

1513
void setup(){
1614
Serial.begin(115200);
@@ -23,19 +21,18 @@ void loop(){
2321

2422
Serial.println("Making GET request...");
2523

26-
http.get(resource);
24+
client.get(resource);
2725

28-
int status_code = http.responseStatusCode();
29-
String response = http.responseBody();
26+
int statusCode = client.responseStatusCode();
27+
String response = client.responseBody();
3028

3129
Serial.print("Status code: ");
32-
Serial.println(status_code);
30+
Serial.println(statusCode);
3331
Serial.print("Response: ");
3432
Serial.println(response);
3533

36-
http.stop();
34+
client.stop();
3735

3836
delay(5000);
3937

4038
}
41-

examples/HTTPSClient/HTTPSClient.ino

+8-11
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#include <ArduinoHttpClient.h>
55
#include "arduino_secrets.h"
66

7-
87
const char server[] = "example.com";
98
const char resource[] = "/";
109
const int port = 443;
1110

1211
ArduinoCellular cellular = ArduinoCellular();
13-
HttpClient http = cellular.getHTTPSClient(server, port);
12+
HttpClient client = cellular.getHTTPSClient(server, port);
1413

1514
void setup(){
1615
Serial.begin(115200);
@@ -20,21 +19,19 @@ void setup(){
2019
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
2120
}
2221

23-
void loop()
24-
{
22+
void loop(){
2523
Serial.println("Making GET request...");
2624

27-
http.get(resource);
25+
client.get(resource);
2826

29-
int status_code = http.responseStatusCode();
30-
String response = http.responseBody();
27+
int statusCode = client.responseStatusCode();
28+
String response = client.responseBody();
3129

3230
Serial.print("Status code: ");
33-
Serial.println(status_code);
31+
Serial.println(statusCode);
3432
Serial.print("Response: ");
3533
Serial.println(response);
3634

37-
http.stop();
38-
35+
client.stop();
3936
delay(5000);
40-
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#include "ArduinoCellular.h"
22
#include "arduino_secrets.h"
33

4+
// #define TINY_GSM_DEBUG Serial
5+
// #define ARDUINO_CELLULAR_DEBUG
46

5-
6-
#define TINY_GSM_DEBUG Serial
7-
#define ARDUINO_CELLULAR_DEBUG
7+
constexpr int NEW_SMS_INTERRUPT_PIN = A0;
88

99
ArduinoCellular cellular = ArduinoCellular();
10-
11-
boolean newSMS = false;
12-
10+
volatile boolean newSMSavailable = false;
1311

1412
void printMessages(std::vector<SMS> msg){
1513
for(int i = 0; i < msg.size(); i++){
@@ -20,18 +18,20 @@ void printMessages(std::vector<SMS> msg){
2018
}
2119
}
2220
void newSMSCallback(){
23-
Serial.println("new sms received");
24-
newSMS = true;
21+
Serial.println("New SMS received!");
22+
newSMSavailable = true;
2523
}
2624

2725
void setup(){
2826
Serial.begin(115200);
2927
while (!Serial);
28+
3029
cellular.begin();
30+
Serial.println("Connecting...");
3131
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
3232

33-
34-
attachInterrupt(digitalPinToInterrupt(A0), newSMSCallback, RISING);
33+
// Register interrupt based callback for new SMS
34+
attachInterrupt(digitalPinToInterrupt(NEW_SMS_INTERRUPT_PIN), newSMSCallback, RISING);
3535

3636
Serial.println("Read SMS:");
3737
std::vector<SMS> readSMS = cellular.getReadSMS();
@@ -40,16 +40,14 @@ void setup(){
4040
Serial.println("Unread SMS:");
4141
std::vector<SMS> unreadSMS = cellular.getUnreadSMS();
4242
printMessages(unreadSMS);
43-
44-
cellular.sendSMS("+40788494946", "bleep bleep");
4543
}
4644

4745
void loop(){
48-
if(newSMS){
49-
newSMS = false;
46+
if(newSMSavailable){
47+
newSMSavailable = false;
5048
std::vector<SMS> unreadSMS = cellular.getUnreadSMS();
5149
if (unreadSMS.size() > 0){
5250
printMessages(unreadSMS);
5351
}
5452
}
55-
}
53+
}

0 commit comments

Comments
 (0)