2

Here I am using Arduino uno and GSM sim900A, I want to read sms from sim900A. But i am trying to read message, it is showing the empty values. I tried different methods, but no use. Here I have added my script. Please help me.

#include <avr wdt.h="">  
String phoneSMS = "+91xxxxxxxxxx";  
String messageTxt;  
void setup()  
{  
Serial.begin(9600);  
delay(60000);  
srl_msg();  
}  
String srl_msg()  
{  
Serial.println("AT+CMGF=1\r");  
delay(1000);  
Serial.println("AT+CNMI=2,2,0,0,0");  
delay(1000);  
Serial.println("AT+CMGL=\"ALL\"\r"); // to read ALL the SMS in text mode  
delay(1000);  
char txtmsg2[100]; // AT command output  
String date = readSerial(txtmsg2);  
String value = date.substring(1, 50);  
messageTxt = "Internal - Heart Beat;";  
messageTxt.concat(value);  
Serial.println(value);  
SendSMS(messageTxt);  
}  
void loop()  
{  
}  
void SendSMS(String message)  
{  
Serial.print("at+cmgf=1\r");  
delay(1000);  
Serial.print("at+cmgs=\"");  
Serial.print(phoneSMS);  
Serial.println("\"");  
delay(1000);  
Serial.println(message);  
delay(1000);  
Serial.print((char)26);  
delay(15000); // AAN  
}  
String readSerial(char result[])  
{  
int i = 0;  
while (Serial.available() > 0)  
{  
char inChar = Serial.read();  
if (inChar != '\r')  
{  
result[i] = inChar;  
i++;  
}  
}  
return result;  
}  

output is look like this: AT+CMGF=1

OK

AT+CNMI=2,2,0,0,0

OK
AT+CMGL="ALL"

OK

1

Check you sim card inbox. I also had the same problem, and it turns out the sim card sms inbox capacity is full.
You can also try to use another library, here is one of them

0

wdt.h is just time handling data library, and have no methods for send or receive sms...

Your method: SendSMS(String message)

is just printing serial labels and counting a char that you are putting in the serial monitor.

Try this GSM example...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.