sheng xiaolin
/
Nucleo_GPRS_sim808
learning AT command
Fork of Nucleo_sim808_GPRS by
main.cpp
- Committer:
- shawlinrise
- Date:
- 2017-06-11
- Revision:
- 0:e791ad8b9e26
- Child:
- 1:79272efb4415
File content as of revision 0:e791ad8b9e26:
#include "mbed.h" #include "string.h" Serial pc(SERIAL_TX, SERIAL_RX); Serial sim808(D1,D0); DigitalOut myled(LED1); #define buf_max 200 int First_Int = 0; char sim_buf[buf_max]; char *phone="\"17865578811\"";//¶ÌÐŽÓÊÕ·½ÊÖ»úºÅ char *content="HELLO ~";//·¢ËͶÌÐÅÄÚÈÝ char CtrlZ = 0x1A; char temp[50]="AT+CMGS="; void SIM808_IRQHandler(void); void CLR_Buf(void); void Wait_CREG(void); //void getline(); void SIM808_IRQHandler(void) { sim_buf[First_Int] = sim808.getc(); First_Int++; } //void callback() //{ // getline(); //} int main() { pc.baud(115200); sim808.baud(115200); sim808.attach(&SIM808_IRQHandler,SerialBase::RxIrq); pc.printf("Send Message Test!"); wait(1); sim808.printf("AT"); sim808.printf("\r\n"); wait(1); pc.printf("%s",sim_buf); CLR_Buf(); Wait_CREG(); pc.printf("Register Succeed! "); sim808.printf("AT+CMGF=1"); sim808.printf("\r\n"); wait(1); pc.printf("%s",sim_buf); CLR_Buf(); sim808.printf("AT+CSCS=\"GSM\""); sim808.printf("\r\n"); wait(1); pc.printf("%s",sim_buf); CLR_Buf(); sim808.printf("AT+CSMP=17,167,240"); sim808.printf("\r\n"); wait(1); pc.printf("%s",sim_buf); CLR_Buf(); strcat(temp,(char*)phone); sim808.printf("%s",temp); sim808.printf("\r\n"); wait(1); pc.printf("%s",sim_buf); CLR_Buf(); sim808.printf("%s",(char*)content); sim808.printf("%c",CtrlZ); pc.printf("%s",sim_buf); CLR_Buf(); while(1); } //void getline() //{ // pc.putc(sim808.getc()); //} void CLR_Buf(void) { uint16_t k; for(k=0;k<buf_max;k++) //½«»º´æÄÚÈÝÇåÁã { sim_buf[k] = 0x00; } First_Int = 0; //½ÓÊÕ×Ö·û´®µÄÆðʼ´æ´¢Î»Öà } //u8 Find(char *a) //{ // if(strstr(sim_buf,a)!=NULL) // return 1; // else // return 0; //} void Wait_CREG(void) { int i; int k; i = 0; CLR_Buf(); while(i == 0) { CLR_Buf(); sim808.printf("AT+CREG?"); sim808.printf("\r\n"); wait(1); pc.printf("%s\r\n",sim_buf); for(k=0;k<buf_max;k++) { if(sim_buf[k] == ':') { if((sim_buf[k+4] == '1')||(sim_buf[k+4] == '5')) { i = 1; break; } } } pc.printf("CREGING.....\r\n"); } }