Skip to content

Commit d4b6e02

Browse files
committed
Add index property to SMS
1 parent 8027c97 commit d4b6e02

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/ArduinoCellular.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ SMS parseSMSEntry(const String& entry, const String& message) {
272272
int fourthQuoteIndex = entry.indexOf('"', thirdQuoteIndex + 1);
273273
int commaIndexBeforeTimestamp = entry.lastIndexOf(',', entry.lastIndexOf(',') - 1);
274274

275+
String command = "+CMGL: ";
276+
// Index is between "+CMGL: " and first "," symbol
277+
sms.index = entry.substring(entry.indexOf(command) + command.length(), entry.indexOf(',')).toInt();
278+
275279
// Extracting number and raw timestamp
276280
sms.number = entry.substring(thirdQuoteIndex + 1, fourthQuoteIndex);
277281
String rawTimestamp = entry.substring(commaIndexBeforeTimestamp + 2, entry.indexOf('+', commaIndexBeforeTimestamp) + 3);

src/ArduinoCellular.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum ModemModel {
3737
class SMS {
3838
public:
3939
String number; /**< The phone number associated with the SMS. */
40+
int16_t index; /**< The index of the SMS message. */
4041
String message; /**< The content of the SMS message. */
4142
Time timestamp; /**< The timestamp when the SMS was received. */
4243

@@ -46,18 +47,19 @@ class SMS {
4647
*/
4748
SMS() {
4849
this->number = "";
50+
this->index = -1;
4951
this->message = "";
5052
this->timestamp = Time();
5153
}
5254

5355
/**
5456
* Constructor for SMS.
57+
* @param index The index of the SMS message.
5558
* @param number The phone number associated with the SMS.
5659
* @param message The content of the SMS message.
5760
* @param timestamp The timestamp when the SMS was received.
5861
*/
59-
SMS(String number, String message, Time timestamp) {
60-
this->number = number;
62+
SMS(int16_t index, String number, String message, Time timestamp) {
6163
this->message = message;
6264
this->timestamp = timestamp;
6365
}

0 commit comments

Comments
 (0)