send message and call does not work

I have put this code in an arduino mega 2560 with a module a6 gsm connected in serial1. I have put the internal LED as control, the led turns on but does not execute the functions sendMSM() and makeCall() .

any ideas?

String input;
const byte Led = 13;
String telefono;
String mensajesms;
int longitudmensaje;

void setup() {
  pinMode(Led, OUTPUT);
  Serial1.begin(9600);

  Serial.begin(9600);
//  delay(500);

}


void loop()
{
   while (Serial.available())
   {
      char character = Serial.read();
      input.concat(character);
      delay(10);
      
    }


 if (input.endsWith("%")== true){
   telefono=(input.substring(0,10));
   longitudmensaje=(input.length());
   mensajesms=(input.substring(11,longitudmensaje));
   sendMSM();
   delay(7000);
   makeCall();
   digitalWrite(Led, HIGH);
   input="";
 }
   
}
 

void sendMSM() {
   digitalWrite(Led, LOW);
   Serial1.println("AT+CMGF=1");
   delay(2000);
   Serial1.print("AT+CMGS=\"");
   Serial1.print(telefono); 
   Serial1.print(char(34));  // "
   Serial1.print(char(13));  // CR
   Serial1.print('\r');  // hex equivalent of newline
   delay(2000);
   Serial1.print(mensajesms);
   delay(500);
   Serial1.println (char(26));  //ctrl_z
  }

void makeCall() {
  // delay(10000);
   digitalWrite(Led, HIGH);
   // Serial1.println("AT");
   // delay(1000);
   Serial1.print("ATD");
   Serial1.println(telefono);
   delay(20000);
   Serial1.println("ATH");
}

the message is sent from a program made in delphi using the main serial port of the arduino that is connected by usb.

The led turns on, so I understand that the verification is fine.

If I use this code to test the functions, everything works fine.

I really have no idea what might be happening.

char phone_no[]="8293353345";
char caracter;
String comando;


void setup() {
Serial1.begin(9600);
delay(300); 
Serial1.println("AT+CMGF=1");    
delay(2000);
Serial1.print("AT+CMGS=\"");
Serial1.print(phone_no); 
Serial1.write(0x22);
Serial1.write(0x0D);  // hex equivalent of Carraige return    
Serial1.write(0x0A);  // hex equivalent of newline
delay(2000);
Serial1.print("GSM A6 test message!");
delay(500);
Serial1.println (char(26));//the ASCII code of the ctrl+z is 26

delay(10000);
Serial1.println("AT");
delay(1000);
Serial1.print("ATD");
Serial1.println(phone_no);
//Serial.println(";");
delay(20000);
Serial1.println("ATH");

}


void loop()
{
   
}

I really have no idea what might be happening.

Do you plan to read the responses? Or, are you all talk?

I suspect the latter, since you never read what the a6 gsm module has to say about the AT commands you send it.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

PaulS:
Do you plan to read the responses? Or, are you all talk?

I suspect the latter, since you never read what the a6 gsm module has to say about the AT commands you send it.

I agree with you and in the 2nd part of this project, I will see how to receive the module responses in the program made in delphi, in order to control what happens.

but now I need to know why it does not execute the functions, but the led turns on

Robin2:
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

I have used the calse String because I do not have the exact number of characters to receive. If I assign a number of bytes and they are not enough, the string of characters will be incomplete. On the contrary, if I have more, I would be wasting Arduino's memory.

Anyway, if you have a small example based on the code that I have written, I would like your help, to see how it works with your idea.

The problem I have now is that apparently the string arrives well, but the functions are not executed and I do not know why.

luk2009:
I have used the calse String because I do not have the exact number of characters to receive. If I assign a number of bytes and they are not enough, the string of characters will be incomplete. On the contrary, if I have more, I would be wasting Arduino's memory.

What else were you planning to do with the "wasted memory" - you can't sell it on EBay.

Wasted memory is a lot less trouble than a program crash.

And it's not actually wasted anyway because you must have at least that much spare memory for the String class to have room to work.

...R