sim900 library, receive sms truncated to 137 characters

Hi, using the function sms.GetSMS(smsPos, n, 20, smsbuffer,160);
and sending a 160 chars sms to arduino i only get 137 from the function

i send this string “+++++++++1+++++++++2+++++++++3+++++++++4+++++++++5+++++++++6+++++++++7+++++++++8+++++++++9+++++++++0+++++++++1+++++++++2+++++++++3+++++++++4+++++++++5+++++++++6”

and i get back this printed on serial, (smsbuffer is 160 but i also tried to use 300) “+++++++++1+++++++++2+++++++++3+++++++++4+++++++++5+++++++++6+++++++++7+++++++++8+++++++++9+++++++++0+++++++++1+++++++++2+++++++++3+++++++”

if i run the AT demo sketch and send at+cmgl="REC UNREAD i get the full 160 characters.

Unfortunately my skills are not enough to fix the library function, nor finding up where the problem is.

This is the modified sketch i use to test sms reads, i am using a mega, the GSM is attached to hardware serial1, i enabled the #define MEGA and disabled the define uno in the library.

#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//this code is based on the example of Arduino Labs.

//Simple sketch to send and receive SMS.

//int numdata;
boolean started = false;
boolean onetimeclear = 1;
boolean startup = 0;

void setup()
  //Serial connection.
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(9600)) {
    started = true;
  } else Serial.println("\nstatus=IDLE");

  if (started) {
    //Enable this two lines if you want to send an SMS.
    //if (sms.SendSMS("3471234567", "Arduino SMS"))
    //Serial.println("\nSMS sent OK");


void loop()
  char smsbuffer[160];
  char n[50];

  if (onetimeclear == 0)
    int x = 1;
    while (x <= 20)
      char del = sms.DeleteSMS(x);
      onetimeclear = 1;

  if (startup == 0)
   char ret_val = gsm.SendATCmdWaitResp("AT+CCLK?", 1000, 100, "", 1);

  if (started) {
    char smsPos = sms.IsSMSPresent(SMS_UNREAD);
    if (smsPos > 0)
      sms.GetSMS(smsPos, n, 20, smsbuffer,160);
      //      if (del == 0)
      //      {
      //        Serial.println("SMS NON cancellato");
      //      }
      //      else if (del == 1)
      //      {
      //        Serial.println("SMS cancellato");
      //      }


Just out of curiosity, what happens if you change the size of smsbuffer, and the value passed to GetSMS()?

Just out of curiosity, what happens if you change the size of smsbuffer, and the value passed to GetSMS()?

If i increase it beyond 160 nothing happens, the result is the same, but i have not tried to decrease below 160.

If i enable the debug of the library i can see the sms being composed on reception up until some point.
If i concatenate (send an sms of more than 160 characters) the second sms is composed of the last couple characters of the FIRST sms and the characters of the second (i have not tried to send a very long concatenated message, just a 170 chars in total.

It seems to me that some timeout in the library prevents the full reception of the serial buffer of the sim900.