Sending SMS via SIM 800

Hello,

I know. There have been similar quastions asked in this forum, but after hours, I still do not get my error.
I’m trying to send a telegram of multiply sensorvalues via SMS.

For sending I use the following code:

void sendCrashNotification(void) {
  telegram = telegram + " \x1A";
  simSerialInOut("AT+CSCS=\"GSM\" \r\n", "OK\r\n", STD_TIMEOUT);
  simSerial.write("AT+CMGS=\"+49123456789\" \r\n");  //not the orignal used number
  
  int lengthTelegram = (int) telegram.length();
    
  const char telegramArray[lengthTelegram];
  telegram.toCharArray(telegramArray, lengthTelegram);
  
  simSerialInOut(telegramArray, "OK\r\n", STD_TIMEOUT);
  
}

and

int simSerialInOut(const char *cmd, const char *expResp, unsigned int timeoutSec) {
  char c = 0;
  int expRespLen = strlen(expResp);
  int sumExp = 0, sumErr = 0;
  unsigned long t1, t2;

  Serial.print("Sending: ");
  Serial.println(cmd);

  simSerial.write(cmd);

  Serial.print("[");

  t1 = millis();

  while (sumExp != expRespLen) {
    if (simSerial.available()) {
      c = simSerial.read();
      if (c > 32 && c < 127) {
        Serial.print(c);
      }
      else {
        Serial.print(".");
      }

      if (c == expResp[sumExp]) sumExp++;
      if (c == errResp[sumErr]) sumErr++;
      if (sumErr == errRespLen) return -1;

    }

    t2 = millis();

    if ((t2 - t1) > (timeoutSec * 1000)) {
      Serial.println("] - Timeout!");
      return 1;
    }
  }

  Serial.println("]");

  return 0;
}

I get the following output on the serial monitor

[AT+CMGF=1…OK…]
Setup Complete!
Sending: AT+CSCS=“GSM”

[AT+CSCS=“GSM”…OK…]
Sending: 100, 102, 35, 17, 63, 63, 35, 17, 61, 63, 35, 17, 62, 63, 35, 17, 60, 62, 35, 17,
[AT+CMGS="+49123456789"…|.100,.102,.35,.17,.63,.63,.35,.17,.61,.63,.35,.17,.62,.63,.35,.17,.60,.62,.35,.17,…] - Timeout!

Got anyone an idea, why the message is not sending?

  int lengthTelegram = (int) telegram.length();
   
  const char telegramArray[lengthTelegram];
  telegram.toCharArray(telegramArray, lengthTelegram);
 
  simSerialInOut(telegramArray, "OK\r\n", STD_TIMEOUT);

You didn't provide room in the array for the terminating NULL, so telegramArray is NOT a string. It is just a char array.

The simSerialInOut() function expects a string as the first argument.

Sending: 100, 102, 35, 17, 63, 63, 35, 17, 61, 63, 35, 17, 62, 63, 35, 17, 60, 62, 35, 17,

What is the modem supposed to do with that? The modem only understands AT commands (with or without lots of data).