Pages: [1]   Go Down
Author Topic: Sending SMS using SIM900 GPRS Shield  (Read 4687 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am using the gprs shield v1.0 with arduino uno and I wish to send an SMS using it. This is the link to shield : http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0
I use the GSM library which comes along with it. https://code.google.com/p/gsm-shield-arduino/

I uploaded the following code to Arduino:

Code:
#include "SIM900.h"
#include <SoftwareSerial.h>

#include "sms.h"
SMSGSM sms;

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

void setup()
{
  //Serial connection.
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is reccomanded to use 4800 or slower.
  if (gsm.begin(9600)){
    Serial.println("\nstatus=READY");
    started=true; 
  }
  else Serial.println("\nstatus=IDLE");
 
  if(started){
    //Enable this two lines if you want to send an SMS.
      int c = sms.SendSMS("+919703894422", "Arduino SMS");
      Serial.println(c);
  }
 
};

void loop()
{
  if(started){
    //Read if there are messages on SIM card and print them.
    if(gsm.readSMS(smsbuffer, 160, n, 20))
    {
      Serial.println(n);
      Serial.println(smsbuffer);
    }
    delay(1000);
  }
};

The sendSMS function returns a value of -1, which is the default value if SMS is not sent.
I went through the library's send SMS function but could not find any bug in it. This is the code:

Code:
char SMSGSM::SendSMS(char *number_str, char *message_str)
{
  char ret_val = -1;
  byte i;
  char end[2];
  end[0]=0x1a;
  end[1]='\0';
/*
  if (CLS_FREE != gsm.GetCommLineStatus()) return (ret_val);
  gsm.SetCommLineStatus(CLS_ATCMD); 
  ret_val = 0; // still not send
*/
  // try to send SMS 3 times in case there is some problem
  for (i = 0; i < 3; i++) {
    // send  AT+CMGS="number_str"
   
    gsm.SimpleWrite(F("AT+CMGS=\""));
    gsm.SimpleWrite(number_str); 
    gsm.SimpleWriteln("\"");
   
#ifdef DEBUG_ON
Serial.println("DEBUG:SMS TEST");
#endif
    // 1000 msec. for initial comm tmout
    // 50 msec. for inter character timeout
    if (RX_FINISHED_STR_RECV == gsm.WaitResp(1000, 500, ">")) {
#ifdef DEBUG_ON
Serial.println("DEBUG:>");
#endif
      // send SMS text
      gsm.SimpleWrite(message_str);
      gsm.SimpleWriteln(end);
  //_cell.flush(); // erase rx circular buffer
      if (RX_FINISHED_STR_RECV == gsm.WaitResp(7000, 5000, "+CMGS")) {
        // SMS was send correctly
        ret_val = 1;

        break;
      }
      else continue;
    }
    else {
      // try again
      continue;

    }
  }

  gsm.SetCommLineStatus(CLS_FREE);
  return (ret_val);
}

I found that when the function writes the SMS text to gsm, it does not receive the desired "+CMGS" from gsm and hence return value is never set to 1. Can someone please tell why this is happening?

I also tried sending the AT commands through a serial monitor and there also I face the same problem. After I write the message and send a Ctrl+Z, it responds with ERROR.

Please help....
Logged

Offline Offline
God Member
*****
Karma: 16
Posts: 597
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

my suggestions could seem obvious but you didn't say anything about the status LED
Does it blink at the rate of 64ms On/3000ms Off ?
And does your sim card need a pincode ? if yes, did you enter it ?

I don't have this shield (mine is a gps/gprs v3, based on the sim908) , and I don't use the library, which takes too much memory for my needs, then I'm not sure I'll be able to help, but I think you should give as much details as  you can (e.g. put your code here,  tell the output you get on the serial monitor...)
   
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Thanks. The Status LED (red) is always ON, the Netlight LED (green) is 64ms On/3000ms Off, which means it is able to find the network. I dont have any PIN for SIM card.

My code using GSM library is given in the above post. Its output is as follows:

Quote
GSM Shield testing.
status=READY
-1

-1 implies that the sms is not sent.

When I dont use the GSM library, I upload the following code to Arduino. It handles the serial communication between the Arduino and shield:

Code:
#include <SoftwareSerial.h>
 
SoftwareSerial GPRS(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array
void setup()
{
  GPRS.begin(9600);               // the GPRS baud rate   
  Serial.begin(9600);             // the Serial port of Arduino baud rate.
 
}
 
void loop()
{
  if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
  {
    while(GPRS.available())          // reading data into char array
    {
      buffer[count++]=GPRS.read();     // writing data into array
      if(count == 64)break;
  }
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero
 
 
  }
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    GPRS.write(Serial.read());       // write it to the GPRS shield
}
void clearBufferArray()              // function to clear buffer array
{
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}                  // clear all index of array with command NULL
}


And then I manually give AT commands for sending SMS using a serial tool. The output in the Serial monitor is as follows:



Only the final step of sending the msg text followed by Ctrl+Z doesn't work.
When I give AT command for reading SMS (AT+CMGR=1), it displays the top SMS successfully. Many other AT commands from the SIM900 datasheet are also working fine. Dont know what happens while sending SMS.  I've also tried feeding the SMS center number but that didn't help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am also using a Seeed GPS shield. I have a Mac computer and can not get sscom on it as it is a Microsoft program. Is there a way to load up the shield and send SMS with the Arduino terminal? What are some basic steps I can use to send an SMS message test without SSCOM and with a T-Mobile 2$ a day unlimited talk/text plan? This is my first post, I am a noob, please be kind! smiley
Logged

Cordoba, Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 10
I love this moment so much I would have sex with it
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I dont know if its any help, but i connected a Nokia 5310 via serial (hyperterminal) and worked with ATcommands.. this one worked:

Code:
AT+CMGF=1  + Enter  //defines text mdoe
AT+CMGS="0123456789", + Enter   //defines receptor
BODY_OF_SMS //Message
Ctrl+Z //SENDS MESSAGE

I think you are missing a "," on your ATcommand (not sure about the " " )
Logged

b'10 bit || !(b'10 bit)

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset



Only the final step of sending the msg text followed by Ctrl+Z doesn't work.
When I give AT command for reading SMS (AT+CMGR=1), it displays the top SMS successfully. Many other AT commands from the SIM900 datasheet are also working fine. Dont know what happens while sending SMS.  I've also tried feeding the SMS center number but that didn't help.
The problem is your error reporting is only giving you basic information (ie ERROR).  You need to enable a more advanced error reporting scheme.  Send the command AT+CMEE=1 in your setup before trying to send a message.  Now when you have an error, you will get a more detailed explaination of what is causing the error by way of an error code which you can look up.

Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Absolutely same problem during SMS sending... Did you find reason or solution...?
Logged

Pages: [1]   Go Up
Jump to: