Hi,
I read a lot here and now it is time for my first post I hope I do it right.
I attached an Adafruit Fona board to my Teensy 3.2. Works fine so far. I can send SMS and retrieve them. The demo from Adafruit works fine.
Only one problem is there (at the moment), I fixed it, but I would like to know why it is there.
This is the code I'm testing:
The interesting part for my problem is:
The format string for sscanf never worked until I changed it to:
The char buffer filled with fona.read() contains a hex D and hex A in front of the "+CMTI: \"SM\",n" and I wonder why do I have them there? I found no sample with a modified format for sscanf - so why do I have this problem and others don't?!
Thanks!
I read a lot here and now it is time for my first post I hope I do it right.
I attached an Adafruit Fona board to my Teensy 3.2. Works fine so far. I can send SMS and retrieve them. The demo from Adafruit works fine.
Only one problem is there (at the moment), I fixed it, but I would like to know why it is there.
This is the code I'm testing:
Code:
void loop() {
char* bufPtr = fonaInBuffer; //handy buffer pointer
if (fona.available()) //any data available from the FONA?
{
int slot = 0; //this will be the slot number of the SMS
int charCount = 0;
//Read the notification into fonaInBuffer
do {
*bufPtr = fona.read();
Serial.write(*bufPtr);
delay(1);
} while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-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)) {
Serial.print("slot: "); Serial.println(slot);
char callerIDbuffer[32]; //we'll store the SMS sender number in here
// Retrieve SMS sender address/phone number.
if (! fona.getSMSSender(slot, callerIDbuffer, 31)) {
Serial.println("Didn't find SMS message in slot!");
}
Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);
//Send back an automatic response
Serial.println("Sending reponse...");
if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
// delete the original msg after it is processed
// otherwise, we will fill up all the slots
// and then we won't be able to receive SMS anymore
if (fona.deleteSMS(slot)) {
Serial.println(F("OK!"));
} else {
Serial.println(F("Couldn't delete"));
}
}
}
}
The interesting part for my problem is:
Code:
if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) {
The format string for sscanf never worked until I changed it to:
Code:
if (1 == sscanf(fonaNotificationBuffer, "%*c%*c+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) {
The char buffer filled with fona.read() contains a hex D and hex A in front of the "+CMTI: \"SM\",n" and I wonder why do I have them there? I found no sample with a modified format for sscanf - so why do I have this problem and others don't?!
Thanks!