user39835: I know that there is something wrong in my code bellow because I don't get "OK" as response in the SMS when I use Serial.print ("AT") . "AT" is an AT command.
I am using the example 2 of http://forum.arduino.cc/index.php?topic=396450.0
I tested the code bellow on the serial monitor and I am able to see the response of the AT commands on the serial monitor with Debug.println(receivedChars);. However, I am unable to receive the command's response in the SMS and would like to know what is wrong in this procedure. When I upload this code bellow, I only see "AT" in the SMS without the "OK". I think that SW_Serial.print(receivedChars); should show give OK in the SMS but I don't see it.Do you kmow why?

user10794: You are making the mistake of hoping the serial response will come very quickly. You are checking for serial available, which is good, but the function PrintModemResponse gives up once no serial is available. This is quite likely to be before all of the data has arrived. Imagine you are listening to me talking, and you assume that if there is a brief pause (as I take a breath) that my sentence is over. You are better off reading until you get a definite "end marker" like a newline.
I notice you are doing something like that in recvWithEndMarker.
You may find my page about how to process incoming serial data without blocking helpful. Example code from that page:
/*
Example of processing incoming serial data without blocking.

Author:   Nick Gammon
Date:     13 November 2011. 
Modified: 31 August 2013.

Released for public use.
*/

// how much serial data we expect before a newline
const unsigned int MAX_INPUT = 50;

void setup ()
  {
  Serial.begin (115200);
  } // end of setup

// here to process incoming serial data after a terminator received
void process_data (const char * data)
  {
  // for now just display it
  // (but you could compare it to some value, convert to an integer, etc.)
  Serial.println (data);
  }  // end of process_data

void processIncomingByte (const byte inByte)
  {
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

  switch (inByte)
    {

    case '\n':   // end of text
      input_line [input_pos] = 0;  // terminating null byte

      // terminator reached! process input_line here ...
      process_data (input_line);

      // reset buffer for next time
      input_pos = 0;  
      break;

    case '\r':   // discard carriage return
      break;

    default:
      // keep adding if not full ... allow for terminating null byte
      if (input_pos < (MAX_INPUT - 1))
        input_line [input_pos++] = inByte;
      break;

    }  // end of switch

  } // end of processIncomingByte  

void loop()
  {
  // if serial data available, process it
  while (Serial.available () > 0)
    processIncomingByte (Serial.read ());

  // do other stuff here like testing digital input (button presses) ...

  }  // end of loop


39835: <p>I know that there is something wrong in my code bellow because I don't get "OK" as response in the SMS when I use Serial.print ("AT") . "AT" is an AT command.
I am using the example 2 of <a href="http://forum.arduino.cc/index.php?topic=396450.0" rel="nofollow noreferrer">http://forum.arduino.cc/index.php?topic=396450.0</a></p>

<p>I tested the code bellow on the serial monitor and I am able to see the response of the AT commands on the serial monitor with Debug.println(receivedChars);. However, I am unable to receive the command's response in the SMS and would like to know what is wrong in this procedure. When I upload this code bellow, I only see "AT" in the SMS without the "OK". I think that SW_Serial.print(receivedChars); should show give OK in the SMS but I don't see it.Do you kmow why?</p>
 10794: <p>You are making the mistake of hoping the serial response will come very quickly. You are checking for serial available, which is good, but the function PrintModemResponse gives up once no serial is available. This is quite likely to be before all of the data has arrived. Imagine you are listening to me talking, and you assume that if there is a brief pause (as I take a breath) that my sentence is over. You are better off reading until you get a definite "end marker" like a newline.</p>

<p>I notice you are doing something like that in recvWithEndMarker.</p>

<p>You may find my page about <a href="http://www.gammon.com.au/serial" rel="nofollow noreferrer">how to process incoming serial data without blocking</a> helpful. Example code from that page:</p>

<pre><code>/*
Example of processing incoming serial data without blocking.

Author:   Nick Gammon
Date:     13 November 2011. 
Modified: 31 August 2013.

Released for public use.
*/

// how much serial data we expect before a newline
const unsigned int MAX_INPUT = 50;

void setup ()
  {
  Serial.begin (115200);
  } // end of setup

// here to process incoming serial data after a terminator received
void process_data (const char * data)
  {
  // for now just display it
  // (but you could compare it to some value, convert to an integer, etc.)
  Serial.println (data);
  }  // end of process_data

void processIncomingByte (const byte inByte)
  {
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

  switch (inByte)
    {

    case '\n':   // end of text
      input_line [input_pos] = 0;  // terminating null byte

      // terminator reached! process input_line here ...
      process_data (input_line);

      // reset buffer for next time
      input_pos = 0;  
      break;

    case '\r':   // discard carriage return
      break;

    default:
      // keep adding if not full ... allow for terminating null byte
      if (input_pos &lt; (MAX_INPUT - 1))
        input_line [input_pos++] = inByte;
      break;

    }  // end of switch

  } // end of processIncomingByte  

void loop()
  {
  // if serial data available, process it
  while (Serial.available () &gt; 0)
    processIncomingByte (Serial.read ());

  // do other stuff here like testing digital input (button presses) ...

  }  // end of loop
</code></pre>
