1

i have arduino and gsm module sim900 , i want get the number when i receiving message . how can do that is there's command or function in c++ language . thanks

SoftwareSerial SIM900(7, 8);

void setup()
{

 SIM900.begin(19200); // for GSM shield
 SIM900power();  // turn on shield
 delay(10000);  // 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()
{  

 if (SIM900.available() > 0) // if there's Message
  {
   inchar = SIM900.read(); //Get the character from the cellular serial port.
   // command or function for get the phone  number from message
  }
 }
Safaa
  • 31
  • 1
  • 6

1 Answers1

0

Try playing directly with the modem, for example by piping in- and output to your USB serial port, then it will become clearer.

Thing is, when there is a new message, you will get some bytes from the modem looking like this:

+CMTI: "SM",4

...where 4 is the ID. You can then send to the modem AT+CMGR=4 (4 being the ID from earlier) and you'll get a response like this:

+CMGR: "REC UNREAD","+123456789",,"15/04/22,13:22:11+32"
Yay, a nice text message!

OK

If the last part fails, you might first need to tell the modem to read SM type messages, using AT+CPMS="SM".

For more info, see http://www.developershome.com/sms/cmgrCommand2.asp

CherryDT
  • 25,571
  • 5
  • 49
  • 74