Envoi d'un SMS via frdm
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 #include <string> 00003 00004 Serial pc(USBTX, USBRX); // pc comunication 00005 Serial SIM900(D1, D0); //tx, rx SIM 900 00006 string result; 00007 char x; 00008 00009 00010 void clearString() 00011 { 00012 result.clear(); 00013 } 00014 00015 void callback_rx() { 00016 00017 while (SIM900.readable()) { 00018 x = SIM900.getc(); 00019 result += x; 00020 pc.putc(x); // print the answer from SIM900 00021 00022 } 00023 } 00024 00025 void sendSMS() 00026 { 00027 00028 clearString(); 00029 SIM900.printf("AT+CMGF=1\r"); //at command for send sms 00030 wait_ms(1000); 00031 clearString(); 00032 wait_ms(1000); 00033 SIM900.printf("AT+CMGS="); 00034 SIM900.putc('"'); 00035 SIM900.printf("+33669345069"); 00036 SIM900.putc('"'); 00037 SIM900.printf("\r"); 00038 wait_ms(1000); 00039 SIM900.printf("Essai2"); // texte à placer dans le message 00040 wait_ms(1000); 00041 SIM900.putc(0x1A); 00042 wait_ms(5000); 00043 } 00044 00045 00046 int main() { 00047 00048 pc.printf("\r\n GSM 900 TEST\n"); 00049 SIM900.attach(&callback_rx); 00050 SIM900.baud(9600); // 00051 wait_ms(100); 00052 00053 sendSMS(); // SEND SMS 00054 wait_ms(100); 00055 00056 } 00057
Generated on Sat Jul 16 2022 18:29:07 by
1.7.2