Problem regarding SMS Commands sent to GSM SHield.

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 .

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

Read this before posting a programming question

Please note that, at present, the String library has bugs as discussed here and here.

In particular, the dynamic memory allocation used by the String class may fail and cause random crashes.

I recommend reworking your code to manage without String. Use C-style strings instead (strcpy, strcat, strcmp, etc.).

Alternatively, install the fix described here:
http://arduino.cc/forum/index.php/topic,145765

Are these something to do with the String Library?

Only one way to find out. Quit using it.

What GSM shield is it? I've just bought a LinkSprite ATWIN Quad-band GPRS/GSM Shield and am getting the same issues. I'm not using the String library. I'm just communicating with the shield via SoftwareSerial at 9600 on pins D2&D3.

I'm using the code in the second tutorial here:
http://www.linksprite.com/product/showproduct.php?lang=en&id=187
(using the current SoftwareSerial library, and removing the String stuff)

When I try to read an SMS message I'm getting what looks like corruption on the message. If I read the same message several times in a row I get different output. It seems the output corruption seems to start consistently at the 16th byte from the message.

-Matt

mfoobar:
I'm not using the String library.

Here is code from your recent post which suggests you are still using Strings:

#include <String.h>;
String SenderNumber, StatusUpdate, strBuffer;;
SenderNumber = ("0" + strBuffer.substring(10,20));

Edited to add: Sorry, I have just noticed there are two people discussing separate problems on this thread - that wasn't your code I quoted.

Can you post your code?

I think I might have got to the problem with my issue of garbled messages coming through. I set the modem itself to 9600 baud:

AT+IPR=9600

I think it might auto-sense, but for whatever reason that was not working. Now I can reliably get SMSs to/from the modem. Oh and I am now using the String library. And all still seems fine.

-Matt

Hello
I just bought a LinkSprite ATWIN Quad-band and would like to have a program to send an sms
I am a beginner