1

我有arduino和gsm模块sim900,我想在收到消息时得到号码。c++语言中有命令或函数怎么办。谢谢

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
  }
 }
4

1 回答 1

0

尝试直接使用调制解调器播放,例如通过管道输入和输出到您的 USB 串行端口,然后它会变得更清晰。

问题是,当有新消息时,您将从调制解调器中获得一些字节,如下所示:

+CMTI: "SM",4

...4身份证在哪里。然后,您可以发送到调制解调器AT+CMGR=44作为之前的 ID),您将收到如下响应:

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

OK

如果最后一部分失败,您可能首先需要告诉调制解调器读取SM类型消息,使用AT+CPMS="SM".

有关详细信息,请参阅http://www.developershome.com/sms/cmgrCommand2.asp

于 2016-05-03T14:41:00.013 回答