I have a software serial link between an Arduino Uno and a TC35 GSM Module to send and receive SMS messages. Sending SMS'/calls is not a problem as it is a matter of sending the appropriate AT command to the GSM module. However I wish to use the AT+CMGR=1 command (which checks the first SMS stored on the SIM card) to check if there is any messages and store the message as a char array so that I can then check if the SMS contains the word 'on' or 'off' to activate a LED.
The AT+CMGR=1 command should return the following:
AT+CMGR=1
+CMGR: "REC READ","+3538xxxxxxxx",,"13/03/23,14:29:37+00"
Set
OK
But in the method below when I print 'data' it just returns:
Message contains:
AT
Any pointers would be much appreciated.
void checkMessage() {
gsmSerial.println("AT+CMGR=1"); //Reads the first SMS
for (x=0;x < 255;x++){
data[x]='\0';
}
x=0;
do{
while(gsmSerial.available()==0);
data[x]=gsmSerial.read();
x++;
if(data[x-1]==0x0D&&data[x-2]=='"'){
x=0;
}
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
data[x-3]='\0'; //finish the string before the OK
Serial.println("\r\nMessage contains: \r");
Serial.println(data); //shows the message
delay(1000);
}