Skip to content

Commit d7c7e2b

Browse files
committed
Clean up receive SMS example
1 parent fb90af3 commit d7c7e2b

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed
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)