Good day Everyone! I am working on an arduino project with GSM Shield right now. So this is how the project should behave: When somebody sent a message to the gsm shield with a command (in my case, #STATUS), the arduino will then reply a set of information. I have my codes here(part of it I got from the internet).
#include <String.h>;
String SenderNumber, StatusUpdate, strBuffer;;
int ct = 0;
char c, buffer[320];
int ledpin = 22;
void setup()
{
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
Serial1.begin(9600); //GSM
delay(30000);
Serial1.println("AT+CMGF=1"); // set SMS mode to text
delay(200);
Serial1.println("AT+CNMI=1,2,0,0,0 "); // set module to send SMS data to serial out upon receipt
delay(200);
Serial.println("GSM Shield is OK and Ready!");
}
void loop()
{
if (Serial1.available() > 0)
{
c = Serial1.read();
Serial.print(c);
if ((c == '\n'))
{
buffer[ct] = 0;
strBuffer = buffer;
if (strBuffer.substring(0,5) == "+CMT:")
{
SenderNumber = ("0" + strBuffer.substring(10,20));
Serial.println(SenderNumber);
}
if ((strBuffer.substring(0,7) == "#STATUS")) //#STATUS is the kcommand
{
StatusUpdate = "Terminal Monitoring System Status Update"; //This is supposed to be the set of information but for now I just used a string
Serial.println(StatusUpdate);
sendSMS();
int flag = 0;
}
ct = 0;
}
else
{
buffer[ct] = c;
ct += 1;
if (ct >= sizeof(buffer))
{
ct = 0;
}
}
}
}
void sendSMS()
{
Serial1.print("AT+CMGS=\"");
Serial1.print(SenderNumber);
Serial1.print("\"\r");
delay(1000);
Serial1.print(StatusUpdate);
delay(15000);
Serial1.print('0x1A');
digitalWrite(ledpin, HIGH);
}
The Serial Monitor gives me this output:
GSM Shield is OK and Ready!
AT+CMGF=1
OK
AT+CNMI=1,2,0,0,0
OK
+CMT: "+6392293*****","SenderName","13/02/03,02:28:22+32"
092293*****
#STATUS
Terminal Monitoring System Status Update
AT+CMGS="092293*****"
> Terminal Monitoring System Status [color=red]Upd12609[/color]
I am not getting the OK response from the AT+CMGS command and there is something strange in the message body (which I highlighted RED)
I think I am close to what I want to achieve but I am really confused in which part I did wrong.. I really hope you can help me with this. I really want to finish this project. God bless you .