n.n

Dependencies:   mbed

main.cpp

Committer:
QuangAnhLe
Date:
2019-08-05
Revision:
0:5fa883d73460

File content as of revision 0:5fa883d73460:

#include "mbed.h"
#include <string>
 
Serial pc(PA_2,PA_3); // pc comunication
Serial SIM900(PA_9, PA_10);   //tx, rx SIM 900
string result;
char x;
 
 
void clearString()
 {
  result.clear();
  }
 
void callback_rx() {
 
    while (SIM900.readable()) {
      x = SIM900.getc();
      result += x;
    pc.putc(x); // print the answer from SIM900
 
       }
}
 
void sendSMS()
{
 
clearString();
  SIM900.printf("AT+CMGF=1\r"); //at command for send sms
    wait_ms(1000);
clearString();
wait_ms(1000);
SIM900.printf("AT+CMGS=");
SIM900.putc('"');
SIM900.printf("+4917645651571");
SIM900.putc('"');
SIM900.printf("\r");
wait_ms(1000);
SIM900.printf("test1");
wait_ms(1000);
SIM900.putc(0x1A);
wait_ms(5000);
}
 
 
int main() {
 
pc.printf("\r\n GSM 900 TEST\n");
SIM900.attach(&callback_rx);
SIM900.baud(9600); //
wait_ms(100);
 
   
 
wait_ms(10);
sendSMS();  // SEND SMS
 wait_ms(100);
 

 
}