![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
learning the AT command
Fork of Nucleo_sim808_sms by
Revision 0:e791ad8b9e26, committed 2017-06-11
- Comitter:
- shawlinrise
- Date:
- Sun Jun 11 10:28:21 2017 +0000
- Commit message:
- SIM808_SMS
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Jun 11 10:28:21 2017 +0000 @@ -0,0 +1,137 @@ +#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"); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jun 11 10:28:21 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/0f02307a0877 \ No newline at end of file