SMS message truncating at 'W' when sending SMS through SIM900 GSM shield!!

Hi all,

I am trying to make an automated SMS response system using Arduino. For this I have Ethernet Shield, GSM Shield and 2 Arduino UNO board (one for each shield). The way it works is that the server initiates a TCP/IP connection with the Ethernet shield and transfers the SMS to send along with the destination number. The message is then transferred to Arduino with GSM Shield using serial connection. After that the SMS is sent to destination using GSM Shield (SIM 900). But all the message sent in this way gets truncated at the first occurrence of 'w'. For e.g:

If the message if "Hey! How is the work?" then only "Hey! How" is only sent as SMS.

I tried debugging the issue and I have found that the full message is transferred to the Arduino board. But when trying to send the SMS the message gets truncated at 'w'.

Sketches attached in the post!!

Thanks for the help!!

SpiArduinoGSM.ino (1.58 KB)

SpiArduinoEthernet.ino (3.36 KB)

I counted how many characters are not printed, and it coincidentally ends up being 12 characters. Maybe these lines of code have something to do with it?

  char txtMsg[msg1.length()-12]; 
  msg1.substring(13).toCharArray(txtMsg,msg1.length()-12);

edit: Remember to add one character (byte) to the array to allow for the zero terminator. :wink:

  char txtMsg[msg1.length()+1]; 
  msg1.substring(13).toCharArray(txtMsg,msg1.length());

edit2: ...and the Serial.read() call may not return all the characters sent. Here is the complete code you posted with the comment at the Serial.read() call. You should wait for a terminator character (like a line feed) before sending the SMS.

#include <SPI.h>
#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;

void setup()
{
  Serial.begin(9600);
  boolean notConnected = true;
  sendDataToDisplay("Initializing GSM");
  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY))
    {
      notConnected = false;
    }
  }
  sendDataToDisplay("GSM Connected");
}

void loop()
{
// this may not get all the characters sent over the serial port before calling sendSMS()
  if(Serial.available())
  {
    String s=recieveSerialValue();
    sendSMS(s); 
  }
  else
  {
    recieveSMS();
  }
  delay(2000);
}
String recieveSerialValue()
{
  String m="";
  if (Serial.available() > 0) 
  {
    m=Serial.readString();
  }
  return m;
}
void recieveSMS()
{
  char senderNumber[20];
  String message="";
  char c;
  // If there are any SMSs available()  
  if (sms.available())
  { 
    sms.remoteNumber(senderNumber, 20);
    // Read message bytes 
    while(c=sms.read())
    {
      message+=c;
    } 
    sms.flush();
    message=String("1")+senderNumber+String("@")+message;
    Serial.println(message);
  }
}

void sendSMS(String msg1)
{
  char remoteNum[11];  
  //char messageBody[msg1.length()-12]
  msg1.substring(3,13).toCharArray(remoteNum,11);
  char txtMsg[msg1.length()-12]; 
  msg1.substring(13).toCharArray(txtMsg,msg1.length()-12);
  sendDataToDisplay(txtMsg);
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS(); 
  sendDataToDisplay("sms sent to " + String(remoteNum));
}

void sendDataToDisplay(String data)
{
  data='0'+data;
  Serial.println(data);
}

hey SurferTim Thanks for your analysis.

the problem is with character 'w'. If we sent any data with word having w then it is truncated from there. But if we make small w to upper W then it works fine.

Your second edit2: I have used stream.readString (Stream.readString() - Arduino Reference ) . So it will read whole string.

Is there any meaning of small w in AT command or treated as special character.

How are you sending the terminating zero byte? Are you certain it is not the readString function causing the problem with the lower case w? Add a Serial.println() call just before sending the SMS to insure you are sending the entire string.

  if(Serial.available())
  {
    String s=recieveSerialValue();
// add this
    Serial.println(s); 
    sendSMS(s); 
  }

I don't recall any AT commands that use a lower case w, especially as a message terminator. Most AT commands are preceded with AT or an ampersand.

Yes I have done that and it prints whole message.
Even within sendSMS function if print the txtMsg after taking substring then it also prints the exact message( full text).

I don't recall any AT commands that use a lower case w, especially as a message terminator.

I've seen this problem reported before though, with one specific GSM shield. I don't know that there ever was a resolution, other than to not use w in the message.

I think a w (or W?) may be an AT wait for dial tone command.

Thanks guys, now we have changed whole message to upper case so problem is solved temporarily.

Bt if it is AT command then is there any way to send sms properly with 'w' beside not using 'w' or changing to upper case.

I know this is an old thread but this is weird because I am also experiencing this problem. Everything after "w" is not sent in the SMS. I am also using a shield that uses sim900.