2016-04-08 123 views
1

我有arduino和GSM模塊SIM900,我想要收到我收到消息時的號碼。如何才能做到這一點是有c + +語言的命令或功能。感謝arduino和GSM模塊sim900如何獲取短信的電話號碼?

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

回答

0

嘗試通過管道輸入和輸出到您的USB串行端口與調制解調器直接播放,例如,那麼它會變得更加清晰。

事情是,當有新郵件,你會得到來自調制解調器看起來像這樣一些字節:

+CMTI: "SM",4 

...其中4是ID。然後,您可以發送到調制解調器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

相關問題