GPRS SHIELD SIM900 and read SMS

hello

I have a problem with SIM900 GPRS SHIELD …

I want you to read the incoming SMS shield. I want to read the sms text and put it into a variable.

I can not …

have libraries to recommend?

here is a sample code, how can I make readsms?

[code]
#include <SoftwareSerial.h>
#include <String.h>
#include <leOS.h>
SoftwareSerial mySerial(7, 8);
int ledcontrollo = 13; //led di controllo stato sensore PIR

int sen = 10; //porta sensore PIR
int allarme = 0; //variabile di controllo attivazione/disattivazione allarme

void setup()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);

mySerial.begin(19200); //inizializzazione shield gprs
pinMode(sen, INPUT); //pin di input sensore PIR
pinMode(ledcontrollo, OUTPUT);
delay(500);

}
void loop()
{
if (digitalRead(sen) == HIGH){
digitalWrite(ledcontrollo, HIGH);
DialVoiceCall(); }
else{
digitalWrite(ledcontrollo, LOW);}

}

void SendTextMessage()
{
mySerial.print(“AT+CMGF=1\r”); //Because we want to send the SMS in text mode
delay(100);
mySerial.println("AT + CMGS = “+86138000000"”);//send sms message, be careful need to add a country code before the cellphone number
delay(100);
mySerial.println(“A test message!”);//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 DialVoiceCall()
{
mySerial.println(“ATD + +3930000000;”);//dial the number
delay(100);
mySerial.println();
}

void controllo(){
if (digitalRead(sen) == HIGH){
digitalWrite(ledcontrollo, HIGH);}
else{
digitalWrite(ledcontrollo, LOW);}
}
/code]

To read a text in slot 1, you would use the following AT command:

AT+CMGR=1

To store the text, you would first create a string variable and then assign the contents of the text to the string.

Using the code from the GPRS V1.0 Wiki page (http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0)…

[code]//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0; // counter for buffer array
void setup()
{
GPRS.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the Serial port of Arduino baud rate.

}

void loop()
{
if (GPRS.available()) // if date is comming from softwareserial port ==> data is comming from gprs shield
{
while(GPRS.available()) // reading data into char array
{
buffer[count++]=GPRS.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero

}
if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
GPRS.write(Serial.read()); // write it to the GPRS shield
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i++)
{ buffer[i]=NULL;} // clear all index of array with command NULL
}[/code]

…you can see from the comments in the code that this is reading data from the serial module into an array of characters (a string) called “buffer”. Similarly, you could create an array of characters that’s 160 characters long, send the AT command AT+CMGR=1 to read the text you want to read, and then store output from the serial module your array the same way that the example code is doing it.

You could even copy the part of the code above, change the name of the array of chars that your’e using, and then paste it after the AT+CMGR command in your code.

Hope this helps.

Cheers,
Tim G.

bcaruso

Did you resolve your read SMS issue?
Could you post your updated code if you have?

Thanks

What’s your purpose after you put sms text into a variable? And what’s the type of this variable?