# Facing problem on sending SMS on different condition Using GSM module and Arduino mega

**URL:** <https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020>\
**Category:** Programming\
**Created:** [December 18, 2021, 2:32am UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020 "2021-12-18T02:32:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 18, 2021, 2:32am UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/1 "2021-12-18T02:32:35Z")

</div>

I have made a program for sending the condition based sms.But he problem is that the GSM Module send the sms only after first condition become true. Module not sending the sms on other condition even after that's were become true.

Here is my code:-

```cpp
#include <SoftwareSerial.h>

SoftwareSerial GPRS(11, 10);
#include "RTClib.h"///////////////////// rtc
RTC_DS3231 rtc;////////////////////////// rtc
#define deviceAddress 0b1101000

#include <EEPROM.h>
#include <Wire.h>
const byte interruptPin = 2;
const uint8_t EngineCommand = 38;
int EventState = 0;
int EventState1 = 0;
int TempState = 0;
int TempState2 = 0;
int rpmState = 0;
int MtsState = 0;
int MtsState1 = 0;
int MtsState2 = 0;
int MtsState3 = 0;
int MtsState4 = 0;
int MtsState5 = 0;
int MtsState6 = 0;
int addr_secnd = 1;
int addr_Minute = 3;
int addr_hrs2 = 4;
int Hrs1;
int Hours1;
long lastTime = 1;

int NoDecHrs;
float Hmread;
float Hrsread;
int diffrE;
int diffrP;
int diffrT;
int diffrH;
int diffrF;
int addr_HMR = 30;
volatile byte state1 = HIGH;
volatile byte seconds = EEPROM.read(addr_secnd);
volatile byte minutes = EEPROM.read(addr_Minute);
volatile int hours = EEPROM.get(addr_hrs2, hours); //Hours1);
//int hours;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  GPRS.begin(9600);
  rtc.begin();
  GPRS.println("AT+CMGF=1");
  delay(500);

  GPRS.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
  pinMode(EngineCommand, INPUT_PULLUP);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, FALLING);

  setSQW(0x00);
}
String time()
{
  String dataString = "";
  DateTime now = rtc.now();
  dataString += String(now.hour(), DEC);
  dataString += String(':');
  dataString += String(now.minute(), DEC);
  dataString += String(':');
  dataString += String(now.second(), DEC);

  return dataString;
}
void loop()
{
  DateTime now = rtc.now();
  //Serial.println(diffrP);
  //Serial.println(time());
  //Serial.print("timeTxt.txt=");
  String Hours = String(hours) + (".") + String(minutes);
  Hmread = Hours.toFloat();
  diffrP = (NoDecHrs - 60);
  diffrT = (NoDecHrs - 40);
  diffrH = (NoDecHrs - 20);
  diffrF = (NoDecHrs - 10);
  if (digitalRead(EngineCommand) == HIGH)
  {
    while (EventState < 1)
    {

      EEPROM.update(addr_secnd, seconds);
      EEPROM.update(addr_Minute, minutes);
      EEPROM.put(addr_hrs2, hours);
      EEPROM.put(addr_HMR, Hmread);
      EEPROM.get(addr_HMR, Hrsread);
      Serial.println(Hrsread);
      NoDecHrs = Hrsread;
      EventState++;
      ///Serial.println (NoDecHrs);
    }

    if (diffrP > 10)
    {
      Serial.println ("diffrP");
      while (MtsState2 < 1)
      {
        String message = String (" Please ready for PTO maints.: ") + (String) diffrP;

        GPRS.println("AT+CMGS=\"+917xxxxxxxx\"");

        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character

        delay(200);
        MtsState2++;
      }
    }
    if (diffrT > 10)
    {
      Serial.println ("diffrT");
      while (MtsState3 < 1)
      {
        String message = String (" Please ready for Tm maints.: ") + (String) diffrT;

        GPRS.println("AT+CMGS=\"+917xxxxxxxx\"");

        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(200);
        MtsState3++;
      }
    }
    if (diffrE > 10)
    {
      while (MtsState4 < 1)
      {
        Serial.println ("diffrE");
        String message = String (" Please ready for Eng maints.: ") + (String) diffrT;

        GPRS.println("AT+CMGS=\"+917xxxxxxxx\"");

        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(500);
        MtsState4++;
      }
    }
    if (diffrH > 10)
    {
      while (MtsState5 < 1)
      {
        Serial.println ("diffrH");
        String message = String (" Please ready for HYD maints.: ") + (String) diffrH;
        GPRS.println("AT+CMGS=\"+917xxxxxxxx\"");

        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(500);
        MtsState5++;
      }
    }
    if (diffrF > 10)
    {
      Serial.println ("diffrF");
      while (MtsState6 < 1)
      {
        String message = String (" Please ready for FD maints.: ") + (String) diffrF;

        GPRS.println("AT+CMGS=\"+917xxxxxxxx\"");

        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(500);
        MtsState6++;
      }

    }
  }
  // Serial.println(Hours);
  if (digitalRead(EngineCommand) == LOW)
  {
    Serial.println(Hours);
    MtsState = 0;
    MtsState1 = 0;
    MtsState2 = 0;
    MtsState3 = 0;
    MtsState4 = 0;
    MtsState5 = 0;
    MtsState6 = 0;

  }

}
void blink()
{
  if (digitalRead(EngineCommand) == LOW)
  {

    EventState = 0;

    if (lastTime > 0)
    {
      seconds++;
    }
    if (seconds == 4)
    {
      minutes++;
      seconds = 0;
    }

    if (minutes == 2)
    {
      hours++;
      minutes = 0;
    }
    state1 = !state1;

  }
}

void setSQW(uint8_t value) {
  Wire.beginTransmission(deviceAddress); //device address and STSRT command are queued
  Wire.write(0x0E); //Control Register Address is queued
  Wire.write(0x00); //Data for Control Register is queued
  Wire.endTransmission(); //queued information are transferred under ACK; STOP
}//+CMT: "+919xxxxxx

```

Kindly help me to solved the problem.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [December 18, 2021, 7:24am UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/2 "2021-12-18T07:24:51Z")

</div>

Exactly which test is failing ?  
Have you tried printing the variables that the test uses to see whether they are the values that you expect ?

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 18, 2021, 2:54pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/3 "2021-12-18T14:54:08Z")

</div>

Sorry for the late reply

Only first condition sms is sending , other conditions o/p is printing sms is not sending.

Here is my Serial O/P

```cpp
Hours:126.1
Hours:126.1
Hours:126.1
126.10
diffrP:66
diffrT:86
diffrH:106
diffrF:116

```

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 4:19am UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/4 "2021-12-19T04:19:32Z")

</div>

Serial print happened in each condition, but other Sms function not taken place

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [December 19, 2021, 6:22am UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/5 "2021-12-19T06:22:53Z")

</div>

> [@sreekanthmp](#):
>
> ` GPRS.println("AT+CMGF=1");`

Try adding this text mode setting to each block where a message is to be sent. I'm not certain this can only be done only once in setup. I think the default may be the pdu mode and it may revert with each message.

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 9:56am UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/6 "2021-12-19T09:56:03Z")

</div>

> [@cattledog](#):
>
> the pdu mode

Please explain about this ..

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 19, 2021, 10:05am UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/7 "2021-12-19T10:05:45Z")

</div>

there is tons of information about text mode or pdu mode ➜ [SMS Tutorial: Operating Mode: SMS Text Mode and SMS PDU Mode](https://www.developershome.com/sms/operatingMode.asp)

Your `AT+CMGF=1` command sets the text mode which is what you want (to Send SMS Command in Text Mode).

I think it's sticky but often you'll see

```plaintext
AT+CMGF=1
AT+CMGS="+917xxxxxxxx"
> This is the SMS message
<ctrl+Z >

```

to ensure the modem is indeed in the right mode to send

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 2:40pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/8 "2021-12-19T14:40:44Z")

</div>

> [@sreekanthmp](#):
>
> GPRS.println("AT+CMGF=1");

Now its sending the sms only in two condition that is first and last condition . Its did not send the SMS in remaining condition.

here is my code

```arduino
#include <SoftwareSerial.h>

SoftwareSerial GPRS(11, 10);
#include "RTClib.h"///////////////////// rtc
RTC_DS3231 rtc;////////////////////////// rtc
#define deviceAddress 0b1101000

#include <EEPROM.h>
#include <Wire.h>
const byte interruptPin = 2;
const uint8_t EngineCommand = 38;
int EventState = 0;
int EventState1 = 0;
int TempState = 0;
int TempState2 = 0;
int rpmState = 0;
int MtsState = 0;
int MtsState1 = 0;
int MtsState2 = 0;
int MtsState3 = 0;
int MtsState4 = 0;
int MtsState5 = 0;
int MtsState6 = 0;
int addr_secnd = 1;
int addr_Minute = 3;
int addr_hrs2 = 4;
int Hrs1;
int Hours1;
long lastTime = 1;

int NoDecHrs;
float Hmread;
float Hrsread;
int diffrE;
int diffrP;
int diffrT;
int diffrH;
int diffrF;
int addr_HMR = 30;
volatile byte state1 = HIGH;
volatile byte seconds = EEPROM.read(addr_secnd);
volatile byte minutes = EEPROM.read(addr_Minute);
volatile int hours = EEPROM.get(addr_hrs2, hours); //Hours1);
//int hours;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  GPRS.begin(9600);
  rtc.begin();
  GPRS.println("AT+CMGF=1");
  delay(500);

  GPRS.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
  pinMode(EngineCommand, INPUT_PULLUP);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, FALLING);

  setSQW(0x00);
}
String time()
{
  String dataString = "";
  DateTime now = rtc.now();
  dataString += String(now.hour(), DEC);
  dataString += String(':');
  dataString += String(now.minute(), DEC);
  dataString += String(':');
  dataString += String(now.second(), DEC);

  return dataString;
}
void loop()
{

  DateTime now = rtc.now();
  //Serial.println(diffrP);
  //Serial.println(time());
  //Serial.print("timeTxt.txt=");
  String Hours = String(hours) + (".") + String(minutes);
  Hmread = Hours.toFloat();
  diffrP = (NoDecHrs - 60);
  diffrT = (NoDecHrs - 40);
  diffrH = (NoDecHrs - 20);
  diffrF = (NoDecHrs - 10);
  if (digitalRead(EngineCommand) == HIGH)
  {
    while (EventState < 1)
    {

      EEPROM.update(addr_secnd, seconds);
      EEPROM.update(addr_Minute, minutes);
      EEPROM.put(addr_hrs2, hours);
      EEPROM.put(addr_HMR, Hmread);
      EEPROM.get(addr_HMR, Hrsread);
      Serial.println(Hrsread);
      NoDecHrs = Hrsread;
      EventState++;
      ///Serial.println (NoDecHrs);
    }

    if (diffrP > 10)
    {

      if (MtsState2 < 1)
      {
        Serial.print("diffrP:");
        Serial.println(diffrP);
        String message = String (" Please ready for PTO maints.: ") + (String) diffrP;
        GPRS.println("AT+CMGF=1");
        delay(500);
        GPRS.println("AT+CMGS=\"+917987553768\"");
        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character

        delay(200);

        MtsState2++;
      }
    }
    if (diffrT > 10)
    {

      if (MtsState3 < 1)
      {
        Serial.print ("diffrT:");
        Serial.println(diffrT);

        String message = String (" Please ready for Tm maints.: ") + (String) diffrT;
        GPRS.println("AT+CMGF=1");
        delay(500);
        GPRS.println("AT+CMGS=\"+917987553768\"");

        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(200);

        MtsState3++;
      }
    }
    if (diffrE > 10)
    {
      if (MtsState4 < 1)
      {
        Serial.print("diffrE:");
        Serial.println (diffrE);
        String message = String (" Please ready for Eng maints.: ") + (String) diffrT;
        GPRS.println("AT+CMGF=1");
        delay(500);
        GPRS.println("AT+CMGS=\"+917987553768\"");

        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(500);
        MtsState4++;
      }
    }
    if (diffrH > 10)
    {
      if (MtsState5 < 1)
      {
        Serial.print ("diffrH:");
        Serial.println (diffrH);
        String message = String (" Please ready for HYD maints.: ") + (String) diffrH;

        GPRS.println("AT+CMGF=1");
        delay(500);
        GPRS.println("AT+CMGS=\"+917987553768\"");
        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(500);
        MtsState5++;
      }
    }
    if (diffrF > 10)
    {

      if (MtsState6 < 1)
      {
        Serial.print ("diffrF:");
        Serial.println (diffrF);
        String message = String (" Please ready for FD maints.: ") + (String) diffrF;
        GPRS.println("AT+CMGF=1");
        delay(500);
        GPRS.println("AT+CMGS=\"+917987553768\"");
        delay(500);
        GPRS.println (message);
        GPRS.write( 0x1a ); // ctrl+Z character
        delay(500);
        MtsState6++;
      }

    }
  }
  // Serial.println(Hours);
  if (digitalRead(EngineCommand) == LOW)
  {
    Serial.print("Hours:");
    Serial.println(Hours);
    MtsState = 0;
    MtsState1 = 0;
    MtsState2 = 0;
    MtsState3 = 0;
    MtsState4 = 0;
    MtsState5 = 0;
    MtsState6 = 0;

  }

}
void blink()
{
  if (digitalRead(EngineCommand) == LOW)
  {

    EventState = 0;

    if (lastTime > 0)
    {
      seconds++;
    }
    if (seconds == 4)
    {
      minutes++;
      seconds = 0;
    }

    if (minutes == 2)
    {
      hours++;
      minutes = 0;
    }
    state1 = !state1;

  }
}

void setSQW(uint8_t value) {
  Wire.beginTransmission(deviceAddress); //device address and STSRT command are queued
  Wire.write(0x0E); //Control Register Address is queued
  Wire.write(0x00); //Data for Control Register is queued
  Wire.endTransmission(); //queued information are transferred under ACK; STOP
}//+CMT: "+9195756

```

Serial monitor o/p

```arduino
130.10
diffrP:70
diffrT:90
diffrH:110
diffrF:120

```

Expecting favorable advice

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 2:43pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/9 "2021-12-19T14:43:40Z")

</div>

After adding the line`AT+CMGF=1` in the each condition, module sending sms in only first and second condition....Why?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 19, 2021, 2:48pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/10 "2021-12-19T14:48:28Z")

</div>

you might have timing issues and you try to send new commands to your module whilst it is still busy sending the SMS.

➜ after sending an SMS, increase the `delay(200)` to something longer

```cpp
GPRS.write( 0x1a ); // ctrl+Z character
delay(3000); // for example try with 3 seconds 

```

ideally you would listen back every time you send a command and see if the module said OK etc before you take the next step - without trying to second guess the timing with the fixed delays

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 2:53pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/11 "2021-12-19T14:53:05Z")

</div>

yes ...after adjusting delay between the each conditions, its working good.  
thanks

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 19, 2021, 3:09pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/12 "2021-12-19T15:09:33Z")

</div>

good

so next step = listen to the module after each command and wait for the OK (and handle errors)

😉

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 3:23pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/13 "2021-12-19T15:23:41Z")

</div>

Yes ..... I checked with different delayS, in 3sec its sending all sms and i fixed that delay 🙂 😃

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 19, 2021, 3:29pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/14 "2021-12-19T15:29:33Z")

</div>

that's not the point. One day 3s won't be enough and you'll fail again (or it's way too long and your code is slow / blocked for no reason and you might miss stuff)

the best way to handle this is to send the command and then listen to what the module says back to you. once you get the 'OK' (or whatever) you know the command was processed and you can continue.

second guessing the timing on something asynchronous is error prone

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 3:56pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/15 "2021-12-19T15:56:48Z")

</div>

How can achieve that i had insert this line for getting get Module returns "OK"

```cpp
if (GPRS.available())
  {
    String MntIntr=GPRS.readStringUntil('\n');
    Serial.println(MntIntr);
  }

```

its not working!!

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 19, 2021, 4:06pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/16 "2021-12-19T16:06:35Z")

</div>

what's not working?  
sometimes the answer has multiple lines

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 4:14pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/17 "2021-12-19T16:14:11Z")

</div>

its working

here is serial o/p

```cpp
132.10
diffrP:72
AT+CMGF=1
diffrT:92
diffrH:112
diffrF:122

```

i think i have to compare this string with preetrmined string and if condition is true (` AT+CMGF=1`) module will send next sms...am i right?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 19, 2021, 4:26pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/18 "2021-12-19T16:26:13Z")

</div>

yes.

I've a small class StreamDevice that does deal with it.  
I've a small explanation in the French forum ➜ [Gestion de commandes sur port Série](https://forum.arduino.cc/t/gestion-de-commandes-sur-port-serie/686868)  
if you don't read French, google translate can help out  
the code is commented in English and there is a simple example

for your case you would declare

```cpp
#include <StreamDevice.h>
#include <SoftwareSerial.h>
SoftwareSerial GPRS_Serial(11, 10);
StreamDevice GPRS(GPRS_Serial);

```

do a `GPRS_Serial.begin(9600);` in the setup

and then when you want to send a command you can do as before

`GPRS.println("AT+CMGF=1");`

and then await for the OK

```cpp
  GPRS.endCommand("OK", 5000ul); // Once done, tell the StreamDevice that the command is done and we expect to receive an "OK" as part of the answer (wait default to 1s, you can add the timeout as a parameter - herer 5s)

  if (GPRS.awaitKeyword() == KEYWORD_OK) // this is blocking until timeout or correct answer whichever comes first
    Serial.println(F("all good"));
  else
    Serial.println(F("error"));

```

there is also an API to capture the full answer if you need to

---

<div class="post-metadata">

**Author:** ![sreekanthmp](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sreekanthmp](https://forum.arduino.cc/u/sreekanthmp)\
**Post date:** [December 19, 2021, 4:59pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/19 "2021-12-19T16:59:36Z")

</div>

Tomorrow i will try and get back you..

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [December 19, 2021, 5:48pm UTC](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020/20 "2021-12-19T17:48:34Z")

</div>

> [@J-M-L](#):
>
> I think it's sticky but often you'll see

When @sreekanthmp sorts out all his timing issues and gets reliable code, he can go back and test this.

[Next page](https://forum.arduino.cc/t/facing-problem-on-sending-sms-on-different-condition-using-gsm-module-and-arduino-mega/937020.md?page=2)
