AT+CMGS="XXXXXXXXXXX" doesn't recognize number to send SMS message

Hello guys!
I'm developing a simple project using Arduino, SIM800L, DHT11, Ethernet Shield HR911105A and Ground Humidity Sensor.
I'm trying to get a phone number from a sms text, for example: i send a sms Relatorio+55XXXXXXXXXXX <- Phone number
I can extract the phone number from the sms but when i try to use it to send the SMS back, it returns me an ERROR

This is the code:

while(sim.available()>0) { // verifica se há novas mensagens
    Received_SMS = sim.read(); // Designa a mensagem recebida a uma variável
    Serial.print(Received_SMS); // Printa a mensagem recebida
    RSMS.concat(Received_SMS); // Concatena a variável RSMS que está vazia com a variável Received_SMS
    DHT_OK = RSMS.indexOf("Relatorio+55"); //verifica se a palavra Relatorio está presente no sms recebido
    
  }

  //verifica se a variável DHT_OK é diferente de -1 (Caso a variável seja -1 quer dizer que não há mensagem recebida)
  if (DHT_OK != -1) {
    number = getValue(RSMS, 'o', 2);
    Serial.println(F("\nfound DHT request"));//indica que a mensagem Relatorio foi recebida
    Serial.print("Número:" + number);
    Serial.print(F("Umidade do solo = "));
    Serial.print(sensors->ground_humidity);
    Serial.print(F("%"));
    Serial.print(F("\nTemperatura = "));
    Serial.print(sensors->temperature);
    Serial.print(F("C"));
    Serial.print(F("\nUmidade relativa do ar = "));
    Serial.print(sensors->humidity);
    Serial.print(F("%"));
    Serial.print(F("\nPorcentagem de fumaca: "));
    Serial.print(sensors->smoke);
    Serial.print(F("%"));
    Data_SMS = "\nDiagnostico Sala Fria SRMG \nUmidade do solo (Max: 20%): " + String(sensors->ground_humidity, 1) + 
    "%" + "\nTemperatura (Max: 25C): " + String(sensors->temperature, 1) + "C" + "\nUmidade do ar (Max: 20%): " + String(sensors->humidity, 1) +
    "%"+ "\nPorcentagem de fumaca(Max: 20%): " + String(sensors->smoke, 1) + "%";
    Send_Data();
    DHT_OK = -1;
    delay(2000);
  }
 free(sensors); // libera o espaço utilizado pelas variáveis do sensores


String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
        found++;
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }

  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void Send_Data() {
  Serial.println("\nEnviando dados..."); // Displays on the serial monitor
  sim.print(F("AT+CMGF=1\r")); //Prepara o GSM para o modo de SMS
  delay(100);
  sim.print("AT+CMGS=\"" + number + "\"\r"); //phone number
  delay(500);
  sim.print(Data_SMS); //Essa string é enviada como SMS
  delay(500);
  sim.print((char)26); //Finaliza o comando AT
  delay(500);
  sim.println();
  Serial.println(F("Dados enviados."));
  delay(500);
}

This is the error:

AT+CMGF=1

OK
AT+CMGS="+55XXXXXXXXXXX"

ERROR

It looks like you have a trailing newline '\n' there since your closing quote in on a new line.

I removed the \n and the error persists :frowning:

I currently have some problems like that too in a different code.
However to me it looks like that the modem is picky with the timing.
I have a 1000 delay after the CMGS line and no delay between the message, the char line and the empty println line.
However sometimes get an OK without the recipient getting an SMS :–/

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.