Receiving sms example

I currently own the seeedstudio gprs shield, and the only examples and tutorials I have found are for sending calls and text messaging and even http request but nothing about receiving text messages or data? Is there any example or anyone who can help me out. I would like to text commands like forward and then run a function. I have look at the at commands but I am a little bit lost as I a m new to them. Any help or guidance would be appreciated.

What have you tried?

Have you run into any obstacles? What are they? Do you have any questions?

If answers are posted to these questions, I think you might receive a helpful response.

There is some straightforward example code to get the shield to spew text messages out to the serial line as soon as they come in. This basically just involves sending these AT codes to the shield:
AT+CMGF=1
AT+CNMI=2,2,0,0,0

However I have tried using this code, and some other approaches as well to receive texts, but I have not been able to reliably get complete messages. Almost always, characters are dropped and/or the message is truncated. I am wondering if I am configuring something wrong, or if I have a defective shield.

Here is the example code below, cut and pasted from the web site where I found it. Unfortunately the stupid censorware on this forum won’t let me provide a link to this very useful site.


#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

char incoming_char=0;

void setup()
{
Serial.begin(19200); // for serial monitor
SIM900.begin(19200); // for GSM shield
SIM900power(); // turn on shield
delay(20000); // give time to log on to network.

SIM900.print(“AT+CMGF=1\r”); // set SMS mode to text
delay(100);
SIM900.print(“AT+CNMI=2,2,0,0,0\r”);
// blurt out contents of new SMS upon receipt to the GSM shield’s serial out
delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield “power” button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(7000);
}

void loop()
{
// Now we simply display any text that the GSM shield sends out on the serial monitor
if(SIM900.available() >0)
{
incoming_char=SIM900.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
}

I am having the same / similar issue.
UNO r3 with Seeed GPRS Sheild 1.4
The SIMAT+CNMI=2,2,0,0,0 does work to “Blurt” out messages but i cannot successfully read them unless my baud is @ 2400. But i cannot send sms at 2400 only 19,200. Original thread at arudino site.

[code]#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8);

void setup()
{
mySerial.begin(2400); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
Serial.write(mySerial.read());
delay(500);
mySerial.print(“AT+IPR?\r”);
delay(1000);
//mySerial.print(“AT+IPR=19200\r”);
}

void loop()
{
//after start up the program, you can using terminal to connect the serial of gprs shield,
//if you input ‘t’ in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
//if input ‘d’ in the terminal, it will execute DialVoiceCall(), etc.

if (Serial.available())
switch(Serial.read())
{
case ‘t’:
SendTextMessage();
break;
case ‘r’:
ReadSMS();
break;
}
if (mySerial.available())
Serial.write(mySerial.read());
}

///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
mySerial.print(“AT+CMGF=1\r”); //Because we want to send the SMS in text mode
delay(100);
mySerial.println(“AT + CMGS = “+1440#######””);//send sms message, be careful need to add a country code before the cellphone number
delay(100);
mySerial.println(“A test message from My Arduino!”);//the content of the message
delay(100);
mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
mySerial.println();
}

void ReadSMS()
{
mySerial.print(“AT+CMGL=“ALL”\r”); //Because we want to send the SMS in text mode

mySerial.println();
}

void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}[/code]

If i set the SoftwareSerial baud rate to 2400 and have the AT+IPR set at 0 (auto baud) i can view the message text when i read a text message (in this code, pressing ‘r’) the output is such.

[tt]ÿAT+IPR?

+IPR: 0

OK
AT+CMGL=“ALL”

+CMGL: 1,“REC READ”,"+1440#######","",“14/04/03,12:52:33-16”
Pooo

+CMGL: 2,“REC READ”,"+1440#######","",“14/04/03,12:57:08-16”
Pooopib

+CMGL: 3,“REC READ”,"+1440#######","",“14/04/03,12:57:59-16”
Pooopey

OK

Further, I CANNOT SEND a text message pressing the ‘t’ , the output is such:

AT+CMGF=1
AT + CMGS = “+1440#######”
A test message from My Arduino!

OK[/tt]

Nothing is sent.

When i augment the SoftwareSerial baud to 19200 (i know the code is redundant but want to be verbose):

[code]#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8);

void setup()
{
mySerial.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
Serial.write(mySerial.read());
delay(500);
mySerial.print(“AT+IPR?\r”);
delay(1000);
//mySerial.print(“AT+IPR=19200\r”);
}

void loop()
{
//after start up the program, you can using terminal to connect the serial of gprs shield,
//if you input ‘t’ in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
//if input ‘d’ in the terminal, it will execute DialVoiceCall(), etc.

if (Serial.available())
switch(Serial.read())
{
case ‘t’:
SendTextMessage();
break;
case ‘r’:
ReadSMS();
break;
}
if (mySerial.available())
Serial.write(mySerial.read());
}

///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
mySerial.print(“AT+CMGF=1\r”); //Because we want to send the SMS in text mode
delay(100);
mySerial.println("AT + CMGS = “+14408585040"”);//send sms message, be careful need to add a country code before the cellphone number
delay(100);
mySerial.println(“A test message from My Arduino!”);//the content of the message
delay(100);
mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
mySerial.println();
}

void ReadSMS()
{
mySerial.print(“AT+CMGL=“ALL”\r”); //Because we want to send the SMS in text mode

mySerial.println();
}

///SubmitHttpRequest()
///this function is submit a http request
///attention:the time of delay is very important, it must be set enough

void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}
[/code]

Trying to read text messages with ‘r’ produces

[tt]ÿAT+IPR?

+IPR: 0

OK
AT+CMGL=“ALL”

+CMGL: 1,“REC READ”,"+1440#######","",“14/04/03,12:52:33-16”

+CMGL: 2,“REC READ”,"+1440#######","",“14/04/03,12:57:08-16”

+CMGL: 3,“REC READ”,"+1440#######[/tt]

and respectively pressing t produces:

[tt]AT+CMGF=1

OK
AT + CMGS = “+1440#######”

A test message
+CMGS: 122

OK
[/tt]

The text message sends.

TL;DR: @ 2400 baud i can read text messages but not send
@ 19,200 baud i send text messages but not fully read.

I am not sure what issue i have at hand here? Any ideas?
I’ve tried connecting an external 5v 2a power supply with no change in results.
I’ve tried crating a buffer for softwareSerial.read @64 bytes, but that seeming did not help.
I also tried explicitly setting the baud on the SIM900 to both 2400 and 19,200.