Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 10 months ago.
send SMS with SIM 900
Hi to all, i use a Sim900 of SimCOM if i sand AT command or other commands all work well, but i have a problem for sand a SMS i write this code
#include "mbed.h" #include <string> Serial pc(SERIAL_TX, SERIAL_RX); // pc comunication Serial SIM900(PA_9, PA_10); //tx, rx SIM 900 string result; char x; void power() { sim_power.write(1); // accension gsm wait(1); sim_power.write(0); wait(13); SIM900.printf("ATE0\r\n"); // DISABLE ECHO wait(1); } 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(100); clearString(); wait_ms(100); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+32292*******"); SIM900.putc('"'); SIM900.printf("\r"); SIM900.printf("Example Message SMS"); SIM900.putc(0x1A); wait_ms(20000); } int main() { power(); pc.printf("\r\n GSM 900 TEST\n"); SIM900.attach(&callback_rx); SIM900.baud(9600); // wait_ms(100); while(1) { wait_ms(10); sendSMS(); // SEND SMS wait_ms(100); } }
i see this when i send the sms but i have this strange message: AT+CMGF=1AT+CMGS="+32292*"" Example Message SMS
i see that the system send the message later two loop, i don't know where is the error can you help me?
best regards. A.
4 Answers
7 years, 3 months ago.
Hello I try this project just difference I use sim908c and I do not understand how I do hardware connection if you know please help me
9 years, 8 months ago.
You should use more time between AT commands. eg.
GSM
#include "mbed.h" #include <string> Serial pc(SERIAL_TX, SERIAL_RX); // pc comunication Serial SIM900(PA_11, PA_12); //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("+48*********"); 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); while(1) { wait_ms(10); sendSMS(); // SEND SMS wait_ms(100); } }
8 years, 2 months ago.
i am also getting same issue, not able o send sms please help
Thanks Gautam
You have not declared variable x in callback_rx
posted by Rushabh Shah 01 Nov 2014sorry, i declare char x;
posted by Antoniolinux B. 18 Nov 2014