【问题标题】:arduino and gsm module sim900 how to get messages phone number?arduino 和 gsm 模块 sim900 如何获取消息电话号码?
【发布时间】:2016-04-08 19:33:19
【问题描述】:

我有 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
  }
 }

【问题讨论】:

    标签: arduino gsm sim900


    【解决方案1】:

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

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

    +CMTI: "SM",4
    

    ...4 是 ID。然后您可以发送到调制解调器AT+CMGR=4(4 是之前的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多