Send SMS with STM32l152 and SIM900

2019-09-17 07:11发布

问题:

I send the SMS "Hello World", but on my cellular I get this message ATAT+CMGS="xxxxxx">HelloWorld instead. What can be causing this?

 void controlAT()
{ 
 clearString();  
     wait_ms(100);      
    SIM900.printf("AT\r");
      wait_ms(1000);
if(result=="\r\nOK\r\n") {
 pc.printf("\r\n----OK AT----\r\n");
}else {
     pc.printf("-- ERROR AT --");           
}
pc.printf("%s",result.c_str());     
 }
 /*send SMS */
void sendSMS_Raw()
{
clearString();
SIM900.printf("AT+CMGS=");
SIM900.printf("\"");
SIM900.printf("+xxxxxxxxxxxxx");    
SIM900.printf("\"");
SIM900.printf("\r");
SIM900.printf("Hello World");
SIM900.printf("\r");
SIM900.putc(0x1A); 
wait_ms(200);
pc.printf("%s",result.c_str());     
clearString();  
})
 /**MAIN**/
 int main() {
pc.printf("\r\n GSM 900 TEST\n"); 
SIM900.attach(&callback_rx);    
SIM900.baud(9600); 
wait_ms(100);
      while(1) {

    wait(1.0); // 1 sec
   pc.printf("\r\n---MAIN---\n"); 
    controlAT();            
    sendSMS_Raw();  
        pc.printf("\r\n---FINE---\n"); 

     wait(2.0); // 1 sec

    }
} 

回答1:

the fix it in this metod:

   void sendSMS_Raw()
 {
 pc.printf("\r\n----sendSMS2----\r\n");  
 clearString();
 SIM900.printf("AT+CMGS=");
 SIM900.printf("\"");
 SIM900.printf("+xxxxxxxxx");   
 SIM900.printf("\"");
 SIM900.printf("\r");
 wait_ms(200);      // this create the problem
 SIM900.printf("Hello");
 SIM900.printf("\r");
 SIM900.putc(0x1A); 
 wait_ms(200);
  pc.printf("%s",result.c_str());       
 clearString();                 
 }

thank for all.