Receive reply of AT command by SMS from Arduino

Hi

I am using Arduino UNO with a shield for AT commands.
I am trying to receive an SMS on my cellphone containing the reply of the AT commands sent by the shield.
Fot exemple, I would like to receive the "OK" reply in SMS on my cellphone when my arduino code has the "AT" AT command inside it.
Could you please tell me how I could do it ? is there an exemple?

Thank you

What is a « shield for AT commands » ?
Is that a gsm shield ? If so is it configured to send sms ?
Who will be sending this AT commands?

yes. It's a gsm shield. its programmed to send sms, but the problem is that i can't program it send response of the commands

Do you know how to read a response in a buffer ? If not focus on that first. Typiung AT commands in the serial console, executing them, reading what is coming back and printing it

Then do a piece of code able to send an SMS of a given text to a given number

Then stitch those two together to get what you want

can you tell me what is wrong with this code because this code gives me "ATAT" in sms without OK when I make a call?

int c1 = 0;
String c2 = "";

String atresp()
{
 SW_Serial.print("AT");
 c2 = "";
 delay(100);  
 while(SW_Serial.available() > 0)
 {
   c1= SW_Serial.read();
   c2 += char(c1); 
     
 }
 return c2;
}

MODIFIED*

thank you

here are a few things that are wrong:

1/ you have not read how to use the forum, please read the posts pinned at the top of the forum and use code tags when posting code

2/ don't post snippets.. how can we guess what's the rest of the code. Post full code that compiles; if too big, create a small code demonstrating your issue

3/ is that the way to read the serial line ? this has no chance to be robust as you are second guessing how long it will take to get an answer with your delay(100)... read this tutorial: Serial Input Basics

4/ if your modem is configured in echo mode, then when you type AT it will answer also AT and then the rest of the result of the command

5/ don't use the String class, you'll get weird bugs at some point. use c-strings

J-M-L:
here are a few things that are wrong:

3/ is that the way to read the serial line ? this has no chance to be robust as you are second guessing how long it will take to get an answer with your delay(100)... read this tutorial: Serial Input Basics

4/ if your modem is configured in echo mode, then when you type AT it will answer also AT and then the rest of the result of the command

5/ don't use the String class, you'll get weird bugs at some point. use c-strings

3-there is no delay in those exemples. Does it mean that I shouldn't use it ?
4-I need to add Serial.print("ATE0") ?
5-what are c-strings? ( c-string = char ?)

int c1 = 0;
char c2 = "";

char atresp()
{
 SW_Serial.print("ATE0");

 SW_Serial.print("AT");
 c2 = "";
 while(SW_Serial.available() > 0)
 {
   c1= SW_Serial.read();
   c2 += char(c1); 
     
 }
 return c2;
}

thank you

thanks for using the code tags - much easier to read

3 -> yes, can't deal with the Serial by second guessing when things arrive. (but need to check when bytes are available!) see the tutorial I pointed
4 -> that would help
5 -> read this

the code bellow which I had gave me "ATE0AT?" in the sms. Do you know why ?

char atresp()
{
    Serial.print("ATE0");

  Serial.print("AT");
  c2 = "";
  while(Serial.available() > 0)
  {
    c1= Serial.read();
    c2 += char(c1); 
      
  }
  return c2;
}

Also, I tried to use the "Example 2 - Receiving several characters from the Serial Monitor" of this website Serial Input Basics - updated - Introductory Tutorials - Arduino Forum
and I saw NO CARRIER, and I couldn't send an sms with it. Do you kno why?

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data
boolean newData = false;

void recvWithEndMarker() {
   static byte ndx = 0;
   char endMarker = '\n';
   char rc;
   
   while (Serial.available() > 0 && newData == false) {
       rc = Serial.read();

       if (rc != endMarker) {
           receivedChars[ndx] = rc;
           ndx++;
           if (ndx >= numChars) {
               ndx = numChars - 1;
           }
       }
       else {
           receivedChars[ndx] = '\0'; // terminate the string
           ndx = 0;
           newData = true;
       }
   }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

Give me full code that compiles, using code tags please

which one should I use atresp() or recvWithEndMarker() ? and what is wrong ?

I think that my mistale is in this part of the code .

char c1 = "";
char c2 = "";
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void loop() 
{
    recvWithEndMarker();
    showNewData();

  // put modem into text mode
  SW_Serial.println("AT+CMGF=1");
  delay(250);

  SW_Serial.print("ATE0");
  SW_Serial.print("AT+CMGS=\"");
  SW_Serial.print(DESTINATION_PHONE_NUMBER_PREFIX);
  SW_Serial.print(DESTINATION_PHONE_NUMBER);
  SW_Serial.print("\"\r");
  delay(250);
  
//    SW_Serial.println("AT");
  SW_Serial.println(receivedChars);
//SW_Serial.println(atresp());
 // showNewData();
 
  SW_Serial.write(26); // special "CTRL-Z" character
  SW_Serial.write("\r");

  Debug.println("SMS sent");

  while(1);
}
char atresp()
{
    SW_Serial.print("ATE0");

  SW_Serial.print("AT");
  c2 = "";
  while(SW_Serial.available() > 0)
  {
    c1= SW_Serial.read();
    c2 += char(c1); 
      
  }
  return c2;
}
char recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
   
    SW_Serial.print("AT"); 
    while (SW_Serial.available() > 0 && newData == false) {
        rc = SW_Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
    return receivedChars;
}

void showNewData() {
    if (newData == true) {
        SW_Serial.print("This just in ... ");
        SW_Serial.println(receivedChars);
        newData = false;
    }
}

Is it ok to change the void from" void recvWithEndMarker() " to char as "char recvWithEndMarker()" and to add
return receivedChars; at the end of the char recvWithEndMarker() function ?
. Because when I call that function, I don't get anything in the SMS. What is the right way to call that function in my context?