Skip to content

Commit

Permalink
Fix preferred SMS storage for 3G
Browse files Browse the repository at this point in the history
Version 1.3.3. SMS storage now works properly for 3G.  Also works for
800 and 808. Updated FONA_SMS_Response to work on 3G. Definition of
FONA_PREF_SMS_STORAGE in library is now mandatory.
  • Loading branch information
driverblock committed Aug 29, 2017
1 parent 62ff843 commit 86d783a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Adafruit_FONA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ boolean Adafruit_FONA::begin(Stream &port) {
}

#if defined(FONA_PREF_SMS_STORAGE)
sendCheckReply(F("AT+CPMS=\"" FONA_PREF_SMS_STORAGE "\""), ok_reply);
sendCheckReply(F("AT+CPMS=" FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE "," FONA_PREF_SMS_STORAGE), ok_reply);
#endif

return true;
Expand Down Expand Up @@ -471,9 +471,11 @@ int8_t Adafruit_FONA::getNumSMS(void) {
if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return -1;

// ask how many sms are stored
if (sendParseReply(F("AT+CPMS?"), F("\"SM\","), &numsms))
if (sendParseReply(F("AT+CPMS?"), F(FONA_PREF_SMS_STORAGE ","), &numsms))
return numsms;
if (sendParseReply(F("AT+CPMS?"), F("\"SM_P\","), &numsms))
if (sendParseReply(F("AT+CPMS?"), F("\"SM\","), &numsms))
return numsms;
if (sendParseReply(F("AT+CPMS?"), F("\"SM_P\","), &numsms))
return numsms;
return -1;
}
Expand Down
7 changes: 5 additions & 2 deletions Adafruit_FONA.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
#define FONA3G_A 4
#define FONA3G_E 5

// Uncomment to changed the preferred SMS storage
//#define FONA_PREF_SMS_STORAGE "SM"
// Set the preferred SMS storage.
// Use "SM" for storage on the SIM.
// Use "ME" for internal storage on the FONA chip
#define FONA_PREF_SMS_STORAGE "\"SM\""
//#define FONA_PREF_SMS_STORAGE "\"ME\""

#define FONA_HEADSETAUDIO 0
#define FONA_EXTAUDIO 1
Expand Down
29 changes: 21 additions & 8 deletions examples/FONA_SMS_Response/FONA_SMS_Response.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;

// Use this for FONA 800 and 808s
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Use this one for FONA 3G
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

Expand All @@ -72,16 +75,19 @@ void setup() {
if (imeiLen > 0) {
Serial.print("SIM card IMEI: "); Serial.println(imei);
}


fonaSerial->print("AT+CNMI=2,1\r\n"); //set up the FONA to send a +CMTI notification when an SMS is received

Serial.println("FONA Ready");
}


char fonaInBuffer[64]; //for notifications from the FONA
char fonaNotificationBuffer[64]; //for notifications from the FONA
char smsBuffer[250];

void loop() {

char* bufPtr = fonaInBuffer; //handy buffer pointer
char* bufPtr = fonaNotificationBuffer; //handy buffer pointer

if (fona.available()) //any data available from the FONA?
{
Expand All @@ -92,14 +98,14 @@ void loop() {
*bufPtr = fona.read();
Serial.write(*bufPtr);
delay(1);
} while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-1)));
} while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1)));

//Add a terminal NULL to the notification string
*bufPtr = 0;

//Scan the notification string for an SMS received notification.
// If it's an SMS message, we'll get the slot number in 'slot'
if (1 == sscanf(fonaInBuffer, "+CMTI: \"SM\",%d", &slot)) {
if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) {
Serial.print("slot: "); Serial.println(slot);

char callerIDbuffer[32]; //we'll store the SMS sender number in here
Expand All @@ -109,7 +115,13 @@ void loop() {
Serial.println("Didn't find SMS message in slot!");
}
Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);


// Retrieve SMS value.
uint16_t smslen;
if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println(smsBuffer);
}

//Send back an automatic response
Serial.println("Sending reponse...");
if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) {
Expand All @@ -124,7 +136,8 @@ void loop() {
if (fona.deleteSMS(slot)) {
Serial.println(F("OK!"));
} else {
Serial.println(F("Couldn't delete"));
Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot);
fona.print(F("AT+CMGD=?\r\n"));
}
}
}
Expand Down

0 comments on commit 86d783a

Please sign in to comment.