Receive SMS example

Hello,

Try to receive sms using AT commands with the next code and sending them via serial monitor (configured CR / NL).

#include <SoftwareSerial.h>
#include <string.h>

char incoming_char = 0;
SoftwareSerial cell(2, 3);

void setup()
{
  Serial.begin(9600);
  cell.begin(9600);
  
  Serial.print("Starting modem communication...");
  delay(12000);
  Serial.print("OK\nIntroduce your AT commands:\n"); 
}

void loop()
{
  if(cell.available() > 0)
  {
    incoming_char=cell.read();
    if((incoming_char >= ' ') && (incoming_char <= 'z'))
      Serial.print(incoming_char);
    else
    {
      Serial.print("%");
      Serial.print((int)incoming_char);
      Serial.print("%");
      if(incoming_char==10)
        Serial.println();
    }
  }

  if(Serial.available() > 0)
  {
    incoming_char = Serial.read();
    cell.print(incoming_char);
  }
}

The AT commands for receiving SMS are:

ATE1 --> Set echo ON
AT+CMGF=1 --> Establishes text mode in modem
AT+CMGL="REC UNREAD",1 --> Checks if exists unread SMS. Return OK if not exist any SMS, in other case returns a list with them (the first number of each of them are the index of each of them).
AT+CMGR=[sms_index],0 --> Read SMS with index sms_index from modem memory (ej: AT+CMGR=1,0).
AT+CMGD=[sms_index] --> Delete SMS with index sms_index from modem memory (ej: AT+CMGD=1).

The problem can be attached with your local operator. Are you using the SIM that came with the shield?.

I live in Canada and the SIM card that was provided did not work here. So I am using a Fido/Rogers SIM card. I will try this code out now.

I could not get the codes to work, so I changed this (the 10 to 11) because of the + coming in front.

      Serial.print("%");
      Serial.print((int)incoming_char);
      Serial.print("%");
      if(incoming_char==11)
        Serial.println();
    }

So to clarify the issue - the gsm picks up the first text message coming in but not any others that comes in after unless it is reset

I appreciate the help guys.

Did you manage to execute the AT dialogue? When you execute the sketch you shall see the modem answers. May you copy here the output received through the Serial monitor?

thanks.

ATE1 --> Set echo ON
AT+CMGF=1 --> Establishes text mode in modem
AT+CMGL="REC UNREAD",1 --> Checks if exists unread SMS. Return OK if not exist any SMS, in other case returns a list with them (the first number of each of them are the index of each of them).
AT+CMGR=[sms_index],0 --> Read SMS with index sms_index from modem memory (ej: AT+CMGR=1,0).
AT+CMGD=[sms_index] --> Delete SMS with index sms_index from modem memory (ej: AT+CMGD=1).

I'm not sure if I understood what to do with these commands guys.

After I executed the given code, all I got was:


Starting modem communication...OK
Introduce your AT commands:


Nothing else occurred after I had texted the SIM card number either.

Thanks for the help guys - You guys are my lifeline right now!

I would like to notify that I am using the mega, so would the line:
SoftwareSerial cell(2, 3);

Would be different, or no ?

Thanks guys

First of all, sorry for the delay answering. Long holiday in Madrid.

And yes, things are a bit different in a Mega because interrupts are not the same and communications between modem and arduino have to change.

First, go to the library file called GSM3SoftSerial.cpp and uncomment the lines:

// These can be used in Arduino Mega
#define TXPIN 11
#define RXPIN 10
#define RXINT 4

Now you have to throw a couple of wires:

  • From the shield pin called "GSM TX" to pin number 10
  • From the shield pin called "GSM RX" to pin number 11

Now you should be able to execute the AT commands and see the answers. Please tell us how it is going.

If you move to UNO remember to take out the wires and comment again the lines.

Hey guys,

Thanks for your help - the service was mistakenly cut off.
Akash

Hi, I hope you guys can help me. I can use the following code to receive SMS messages, and then use the body of the SMS message to do some conditional programming. The only problem is that I can only do it by typing my AT commands into the serial monitor. When I try to put the receive SMS command (AT+CMGR=1,0) in my loop, it doesn't work. Ideally I would be able to check for a new SMS every 30 seconds. This is the working code:

#include <SoftwareSerial.h>
#include <string.h>
char command = 0; //Conditional Programming Variable changes with SMS content.
char incoming_char = 0;
SoftwareSerial cell(7, 8); //my shield uses these pins for software serial.

void setup()
{
  Serial.begin(19200);
  cell.begin(19200);
  delay(2000);
  Serial.print("Starting modem communication...");
  delay(12000);
  Serial.print("OK\nIntroduce your AT commands:\n"); 
}

void loop()

{
  if(cell.available() > 0)
  {
    incoming_char=cell.read();
    if((incoming_char >= ' ') && (incoming_char <= 'z'))
      Serial.print(incoming_char);
    if(incoming_char=='#'){
      Serial.println("SMS command mode:"); //If the SMS contains "#" the arduino looks for commands that follow.
      command=cell.read();
    }
    if (command == 'a'){  //If the next character in the SMS is "a", then do the following
      Serial.println("Commands would execute here and now.");
      command = 0;
    }

    else
    {
      Serial.print("%");
      Serial.print((int)incoming_char);
      Serial.print("%");
      if(incoming_char==10)
        Serial.println();

      //Serial.println(incoming_char);



    }
  }

  if(Serial.available() > 0)
  {
    incoming_char = Serial.read();
    cell.print(incoming_char);
  }
}

When I send a SMS to my cell shield that contains "#a" in the body of the message and enter the "AT+CMGR=1,0" into the serial monitor the program reads the SMS and then does whatever I tell it to do. Right now it just executes a serial print that says "Commands would execute here and now".

After I run this I'd also like to delete the SMS with the "AT+CMGD=1" command.

Here is my code with the timed SMS check... It runs the "AT+CMGR=1,0" command every 30 seconds, but doesn't work.

#include <SoftwareSerial.h>
#include <string.h>
char command = 0; //Conditional Programming Variable changes with SMS content.
char incoming_char = 0;
SoftwareSerial cell(7, 8); //my shield uses these pins for software serial.

//These variables are for timing the Receive SMS command.
long previousMillis = 0; //Equals current millis every time interval is met.
long interval = 30000; //Amount of time to wait between Receive SMS commands

void setup()
{
  Serial.begin(19200);
  cell.begin(19200);
  delay(2000);
  Serial.print("Starting modem communication...");
  delay(12000);
  Serial.print("OK\nIntroduce your AT commands:\n"); 
}

void loop()

{ 
//--------Timed SMS Receive command code ---------
  if (currentMillis - previousMillis > interval) {

    cell.print('AT+CMGR=1,0');

    previousMillis = currentMillis;
  }
//------------------------------------------------


  if(cell.available() > 0)
  {
    incoming_char=cell.read();
    if((incoming_char >= ' ') && (incoming_char <= 'z'))
      Serial.print(incoming_char);
    if(incoming_char=='#'){
      Serial.println("SMS command mode:"); //If the SMS contains "#" the arduino looks for commands that follow.
      command=cell.read();
    }
    if (command == 'a'){  //If the next character in the SMS is "a", then do the following
      Serial.println("Commands would execute here and now.");
      command = 0;
    }

    else
    {
      Serial.print("%");
      Serial.print((int)incoming_char);
      Serial.print("%");
      if(incoming_char==10)
        Serial.println();

      //Serial.println(incoming_char);



    }
  }

  if(Serial.available() > 0)
  {
    incoming_char = Serial.read();
    cell.print(incoming_char);
  }
}

The result is this:
"1%49%1%49%3%51%1%49%2%50%"

Which makes no sense to me... I realize I haven't included the auto delete code in either example, that's because I haven't even gotten to that point yet. The previous posts were very helpful, could you please point out what I am doing wrong? I spent all day trying to figure it out. Thanks in advance.

I needed to include a carriage return. I should note I am using the Seeed Studio GPRS shield and not the official arduino shield. I got it to receive messages using AT commands like this:

cell.println("AT+CMGR=1,0");
cell.print("\r");

Thanks to Davidgoth for helping me out via private message.

If anyone is having issues with the this and the seeed studio gprs shield send me a PM, I can probably help you out at this point.

Also it was a lot easier to debug via serial monitor if I took this code chunk and changed it.

else
    {
      Serial.print("%");
      Serial.print((int)incoming_char);
      Serial.print("%");
      if(incoming_char==10)
        Serial.println();
      }
else
    {
      //Serial.print("%");
      Serial.print(incoming_char);
      //Serial.print("%");
      if(incoming_char==10)
        Serial.println();
      }

Just thought I'd resurrect this old girl again. For anyone still having issues with this it can be a simple fix if you are not like me and am having trouble following other peoples code.

Here is the sample code provided by arduino:

/*
 SMS receiver

 This sketch, for the Arduino GSM shield, waits for a SMS message
 and displays it through the Serial port.

 Circuit:
 * GSM shield attached to and Arduino
 * SIM card that can receive SMS messages

 created 25 Feb 2012
 by Javier Zorzano / TD

 This example is in the public domain.

 http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS

*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

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

// Array to hold the number a SMS is retreived from
char senderNumber[20];

void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop()
{
  char c;

  // If there are any SMSs available()
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while (c = sms.read())
      Serial.print(c);

    Serial.println("\nEND OF MESSAGE");

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }
   
  delay(1000);

}

-->Now adding another sms.flush() at the end right before the delay like so:

/*
 SMS receiver

 This sketch, for the Arduino GSM shield, waits for a SMS message
 and displays it through the Serial port.

 Circuit:
 * GSM shield attached to and Arduino
 * SIM card that can receive SMS messages

 created 25 Feb 2012
 by Javier Zorzano / TD

 This example is in the public domain.

 http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS

*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

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

// Array to hold the number a SMS is retreived from
char senderNumber[20];

void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop()
{
  char c;

  // If there are any SMSs available()
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while (c = sms.read())
      Serial.print(c);

    Serial.println("\nEND OF MESSAGE");

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

   sms.flush();//********************right here is what I added************************


  delay(1000);

}

To me, I saw this issue of getting only one SMS at a time to be an issue with how it is stored in the modems memory. It worked for me!! I was able to continually get sms cycling through as they came it.

Looking up the flush() command didn't give me insight into how this really made the code function correctly or buggy and correctly. For whatever reason, I thought I'd bring this up again in hopes the experts can give some insight.

-Rhizz :art:

I can not receive a message , i have a Telit 865 Dual , Can you help to change any things in Library ? is there any things wrong at here ?


#include <GSM3ShieldV1AccessProvider.h>
#include <Arduino.h>
#include "GSM3IO.h"

#define TOUTSHUTDOWN 5000
#define TOUTMODEMCONFIGURATION 5000//equivalent to 30000 because of time in interrupt routine.
#define TOUTAT 1000

const char _command_AT[] PROGMEM = "AT";
const char _command_CGREG[] PROGMEM = "AT+CGREG?";

GSM3ShieldV1AccessProvider::GSM3ShieldV1AccessProvider(bool debug)
{
theGSM3ShieldV1ModemCore.setDebug(debug);

}

void GSM3ShieldV1AccessProvider::manageResponse(byte from, byte to)
{
switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
{
case MODEMCONFIG:
ModemConfigurationContinue();
break;
case ALIVETEST:
isModemAliveContinue();
break;
}
}

///////////////////////////////////////////////////////CONFIGURATION FUNCTIONS///////////////////////////////////////////////////////////////////

// Begin
// Restart or start the modem
// May be synchronous
GSM3_NetworkStatus_t GSM3ShieldV1AccessProvider::begin(char* pin, bool restart, bool synchronous)
{
pinMode(RESETPIN, OUTPUT);

#ifdef TTOPEN_V1
pinMode(POWERPIN, OUTPUT);
digitalWrite(POWERPIN, HIGH);
#endif

// If asked for modem restart, restart
if (restart)
HWrestart();
else
HWstart();

theGSM3ShieldV1ModemCore.gss.begin(9600);
// Launch modem configuration commands
ModemConfiguration(pin);
// If synchronous, wait till ModemConfiguration is over
if(synchronous)
{
// if we shorten this delay, the command fails
while(ready()==0)
delay(1000);
}
return getStatus();
}

//HWrestart.
int GSM3ShieldV1AccessProvider::HWrestart()
{
#ifdef TTOPEN_V1
digitalWrite(POWERPIN, HIGH);
delay(1000);
#endif

theGSM3ShieldV1ModemCore.setStatus(IDLE);
digitalWrite(RESETPIN, HIGH);
delay(12000);
digitalWrite(RESETPIN, LOW);
delay(1000);
return 1; //configandwait(pin);
}

//HWrestart.
int GSM3ShieldV1AccessProvider::HWstart()
{

theGSM3ShieldV1ModemCore.setStatus(IDLE);
digitalWrite(RESETPIN, HIGH);
delay(2000);
digitalWrite(RESETPIN, LOW);
//delay(1000);

return 1; //configandwait(pin);
}

//Initial configuration main function.
int GSM3ShieldV1AccessProvider::ModemConfiguration(char* pin)
{
theGSM3ShieldV1ModemCore.setPhoneNumber(pin);
theGSM3ShieldV1ModemCore.openCommand(this,MODEMCONFIG);
theGSM3ShieldV1ModemCore.setStatus(CONNECTING);
ModemConfigurationContinue();
return theGSM3ShieldV1ModemCore.getCommandError();
}

//Initial configuration continue function.
void GSM3ShieldV1AccessProvider::ModemConfigurationContinue()
{
bool resp;

// 1: Send AT
// 2: Wait AT OK and SetPin or CGREG
// 3: Wait Pin OK and CGREG
// 4: Wait CGREG and Flow SW control or CGREG
// 5: Wait IFC OK and SMS Text Mode
// 6: Wait SMS text Mode OK and Calling line identification
// 7: Wait Calling Line Id OK and Echo off
// 8: Wait for OK and COLP command for connecting line identification.
// 9: Wait for OK.
int ct=theGSM3ShieldV1ModemCore.getCommandCounter();
if(ct==1)
{
// Launch AT
theGSM3ShieldV1ModemCore.setCommandCounter(2);
theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT);
}
else if(ct==2)
{
// Wait for AT - OK.
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
{
if(resp)
{
// OK received
if(theGSM3ShieldV1ModemCore.getPhoneNumber() && (theGSM3ShieldV1ModemCore.getPhoneNumber()[0]!=0))
{
theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CPIN="), false);
theGSM3ShieldV1ModemCore.setCommandCounter(3);
theGSM3ShieldV1ModemCore.genericCommand_rqc(theGSM3ShieldV1ModemCore.getPhoneNumber());
}
else
{
//DEBUG
//Serial.println("AT+CGREG?");
theGSM3ShieldV1ModemCore.setCommandCounter(4);
theGSM3ShieldV1ModemCore.takeMilliseconds();
theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG);
}
}
else theGSM3ShieldV1ModemCore.closeCommand(3);
}
}
else if(ct==3)
{
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
{
if(resp)
{
theGSM3ShieldV1ModemCore.setCommandCounter(4);
theGSM3ShieldV1ModemCore.takeMilliseconds();
theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000);
theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG);
}
else theGSM3ShieldV1ModemCore.closeCommand(3);
}
}
else if(ct==4)
{
char auxLocate1 [12];
char auxLocate2 [12];
prepareAuxLocate(PSTR("+CGREG: 0,1"), auxLocate1);
prepareAuxLocate(PSTR("+CGREG: 0,5"), auxLocate2);
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate1, auxLocate2))
{
if(resp)
{
theGSM3ShieldV1ModemCore.setCommandCounter(5);
theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+IFC=1,1"));
}
else
{
// If not, launch command again
if(theGSM3ShieldV1ModemCore.takeMilliseconds() > TOUTMODEMCONFIGURATION)
{
theGSM3ShieldV1ModemCore.closeCommand(3);
}
else
{
theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000);
theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG);
}
}
}
}
else if(ct==5)
{
// 5: Wait IFC OK
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
{
//Delay for SW flow control being active.
theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000);
// 9: SMS Text Mode
theGSM3ShieldV1ModemCore.setCommandCounter(6);
theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGF=1"));
}
}
else if(ct==6)
{
// 6: Wait SMS text Mode OK
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
{
//Calling line identification
theGSM3ShieldV1ModemCore.setCommandCounter(7);
theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLIP=1"));
}
}
else if(ct==7)
{
// 7: Wait Calling Line Id OK
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
{
// Echo off
theGSM3ShieldV1ModemCore.setCommandCounter(8);
theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATE0"));
}
}
else if(ct==8)
{
// 8: Wait ATEO OK, send COLP
// In Arduino Mega, attention, take away the COLP step
// It looks as we can only have 8 steps
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
{
theGSM3ShieldV1ModemCore.setCommandCounter(9);
theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT#NCIH=1"));
}
}
else if(ct==9)
{
// 9: Wait ATCOLP OK
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
{
if (resp)
{
theGSM3ShieldV1ModemCore.setStatus(GSM_READY);
theGSM3ShieldV1ModemCore.closeCommand(1);
}
else theGSM3ShieldV1ModemCore.closeCommand(3);
}
}
}

//Alive Test main function.
int GSM3ShieldV1AccessProvider::isAccessAlive()
{
theGSM3ShieldV1ModemCore.setCommandError(0);
theGSM3ShieldV1ModemCore.setCommandCounter(1);
theGSM3ShieldV1ModemCore.openCommand(this,ALIVETEST);
isModemAliveContinue();
return theGSM3ShieldV1ModemCore.getCommandError();
}

//Alive Test continue function.
void GSM3ShieldV1AccessProvider::isModemAliveContinue()
{
bool rsp;
switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
case 1:
theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT);
theGSM3ShieldV1ModemCore.setCommandCounter(2);
break;
case 2:
if(theGSM3ShieldV1ModemCore.genericParse_rsp(rsp))
{
if (rsp) theGSM3ShieldV1ModemCore.closeCommand(1);
else theGSM3ShieldV1ModemCore.closeCommand(3);
}
break;
}
}

//Shutdown.
bool GSM3ShieldV1AccessProvider::shutdown()
{
unsigned long m;
bool resp;
char auxLocate [18];

// It makes no sense to have an asynchronous shutdown
pinMode(RESETPIN, OUTPUT);
digitalWrite(RESETPIN, HIGH);
delay(1500);
digitalWrite(RESETPIN, LOW);
theGSM3ShieldV1ModemCore.setStatus(IDLE);
theGSM3ShieldV1ModemCore.gss.close();

m=millis();
prepareAuxLocate(PSTR("POWER DOWN"), auxLocate);
while((millis()-m) < TOUTSHUTDOWN)
{
delay(1);
if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate))
return resp;
}
return false;
}

//Secure shutdown.
bool GSM3ShieldV1AccessProvider::secureShutdown()
{
// It makes no sense to have an asynchronous shutdown
pinMode(RESETPIN, OUTPUT);
digitalWrite(RESETPIN, HIGH);
delay(900);
digitalWrite(RESETPIN, LOW);
theGSM3ShieldV1ModemCore.setStatus(OFF);
theGSM3ShieldV1ModemCore.gss.close();

#ifdef TTOPEN_V1
_delay_ms(12000);
digitalWrite(POWERPIN, LOW);
#endif

return true;
}

Hello,
I want to receive sms using gsm and arduino... I have wrote a program for it, but it's not working. Can you plz check the code and suggest corrections?
Here is my code...

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char RcvdMsg[200] = "";
int RcvdCheck = 0;
int RcvdConf = 0;
int index = 0;
int RcvdEnd = 0;
char MsgMob[15];
char MsgTxt[50];
int MsgLength = 0;
void setup()
{
lcd.begin(16, 2);
lcd.print("Good Afternoon!");
Serial.begin(9600);
Config();

}

void loop()
{
RecSMS();
}

void Config() // This function is configuring our SIM900 module i.e. sending the initial AT commands
{
delay(1000);
Serial.print("ATE0\r");
Response();
Serial.print("AT\r");
Response();
Serial.print("AT+CMGF=1\r");
Response();
Serial.print("AT+CNMI=1,2,0,0,0\r");
Response();
}

void Response() // Get the Response of each AT Command
{
int count = 0;
Serial.println();
while (1)
{
if (Serial.available())
{
char data = Serial.read();
if (data == 'K') {
Serial.println("OK");
break;
}
if (data == 'R') {
Serial.println("GSM Not Working");
break;
}
}
count++;
delay(10);
if (count == 1000) {
Serial.println("GSM not Found");
break;
}
}

}

void RecSMS() // Receiving the SMS and extracting the Sender Mobile number & Message Text
{

if (Serial.available())
{
char data = Serial.read();
if (data == '+') {
RcvdCheck = 1;
}
if ((data == 'C') && (RcvdCheck == 1)) {
RcvdCheck = 2;
}
if ((data == 'M') && (RcvdCheck == 2)) {
RcvdCheck = 3;
}
if ((data == 'T') && (RcvdCheck == 3)) {
RcvdCheck = 4;
}
if (RcvdCheck == 4) {
index = 0;
RcvdConf = 1;
RcvdCheck = 0;
}

if (RcvdConf == 1)
{
if (data == '\n') {
RcvdEnd++;
}
RcvdMsg[index] = data;

index++;
if (RcvdEnd == 2) {
RcvdConf = 0;
MsgLength = index - 2;
RcvdEnd = 0;
}
if (RcvdConf == 0)
{
Serial.print("Mobile Number is: ");
for (int x = 4; x < 17; x++)
{
MsgMob[x - 4] = RcvdMsg[x];
Serial.print(MsgMob[x - 4]);
}
Serial.println();
Serial.print("Message Text: ");
lcd.setCursor(0, 0);
for (int x = 46; x < 62; x++)
{
MsgTxt[x - 46] = RcvdMsg[x];
lcd.print(MsgTxt[x - 46]);
Serial.print(MsgTxt[x - 46]);

}
Serial.println(MsgTxt[0]);
Serial.println(MsgTxt[1]);
Serial.println(MsgTxt[2]);
Serial.println(MsgTxt[3]);
Serial.println(MsgTxt[4]);
lcd.setCursor(0, 1);
for (int x = 62; x < MsgLength; x++)
{
MsgTxt[x - 62] = RcvdMsg[x];
lcd.print(MsgTxt[x - 62]);
Serial.print(MsgTxt[x - 62]);
}
Serial.println();
}
}
}
}

format your code.. and put it in code tags...

otherwise not many people will look at it for you.

hello guyz i have a somewhat similar problem i want to extract the msg(text or body) and the number and date time at which it received of given msg id right now i have successfully communicate the arduino(uno) and gsm module(800l) all AT commands are working fine.
here is the code.

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <string.h>
SoftwareSerial sim(10, 11);

void recmsg();
void setup() {
Serial.begin(9600);
Serial.println("Wait a few seconds...");
delay(5000);
Serial.println("Initializing.");
sim.begin(9600);
delay(1000);

}
void loop() {
if (Serial.available() > 0)
{recmsg();
}

if (sim.available() > 0)
{Serial.write(sim.read());
}}

void recmsg(){
String all="ALL";
char n=0;
//char number[20];
// Serial.println(sim.println("AT+CMGR=16") );
// Serial.println(sim.println("AT+CMGL="" + all + """) );
// Serial.println(sim.println("AT+CMGD=15") );
//Serial.println(sim.println("AT+CMGL="" + all + """) );
//Serial.println(n);
sim.println("AT+CMGR=22");
sim.print("\r");
n=sim.read();

//delay(5000);
Serial.println(n);

}

xl97:
format your code.. and put it in code tags...

otherwise not many people will look at it for you.

Hello to everyone. I'm new to the forum and I'm a student. This is my undergraduate thesis on a track that makes it very difficult for me. So my work is about some measurements that I have to take from a machine and be wirelessly sent to a computer! the first step i have to do is connect a arduino uno to a gps/gprs(gsm 862 Telit). So these two have to receive a message and just transmit it to a server. my problem is i can't code this job.the measurements I take from the machine are stored in a txt file. the measurements have the form (region, time, dates, radiation level). the measurements do not want to be sent to the server via wi-fi because the machine a takes outside measurements away from the wi-fi. Your help is valuable Your help is valuable.
sorry if I'm writing in the wrong place

Hi there everyone,
I hope I can get some direction on the following related problem

I am using the MKR 1400 and it is working fine for me EXCEPT that for some reason there are major delays in receiving the SMS messages whenever they come in rapid sequence.

I am using a slightly modified version of the ReceiveSMS (example sketch) for this test.
The setup is unchanged
Here is the modified loop :

void loop() {
int c;

// If there are any SMSs available()
if (sms.available()) {
Serial.println("Message received from:");

// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);

sms.peek();
delay(100);
sms.flush();
delay(100);
Serial.println("MESSAGE DELETED");
}

sms.flush();
delay(1000);

}

So for example I would send 5 short SMS to the MKR 1400 (each one right after the other )

Then on the serial monitor I would see the first message come in and then some seconds after the 2nd SMS would show up and then several seconds after the 3rd would show and then sometimes the other 2 messages take quite long before they are received.

AND if I take that same telephone SIM and place it in a cellphone and I repeat the same 5 SMS tests ...... ALL 5 SMS would be instantly be received on the cellphone without practically ANY delay. Therefore it is definitely not an issue with the GSM service provider

I just cant figure out what could be causing such large delays on the MRK 1400 board BUT it is really a show stopper for the application I need to run on it.

Any assistance on this matter will be greatly appreciated.