# Problem beim SMS Lesen mit GSM Modul sim800L

**URL:** <https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287>\
**Category:** Deutsch\
**Created:** [November 17, 2019, 8:43pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287 "2019-11-17T20:43:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![DO3GE](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@DO3GE](https://forum.arduino.cc/u/DO3GE)\
**Post date:** [November 17, 2019, 8:43pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/1 "2019-11-17T20:43:42Z")

</div>

Ich lerne noch und versuche das GSM Modul sim800L zu verstehen.

Soweit ok Die ersten Schritte und Demos funktionieren gut.

Nun versuche ich eine SMS mit nachfolgendem Sketch auszulesen.  
Das funktioniert zwar, aber wie bekomme ich den Inhalt der SMS  
in einem String / eine Textvariable.

Ich habe stundenlang versucht und komme nicht weiter kommen.

```cpp
#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM800L
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  
  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

```

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [November 17, 2019, 9:03pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/2 "2019-11-17T21:03:54Z")

</div>

Setze Deinen Code bitte in Codetags (\</\>-Button oben links im Forumseditor oder [_code] davor und [_/code] dahinter ohne \*).  
So ist er auch auf portablen Geräten lesbar. Das kannst Du auch noch nachträglich ändern.

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![uk1408](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/uk1408/32/241543_2.png) [@uk1408](https://forum.arduino.cc/u/uk1408)\
**Post date:** [November 18, 2019, 4:29pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/3 "2019-11-18T16:29:41Z")

</div>

> DO3GE:  
> Nun versuche ich eine SMS mit nachfolgendem Sketch auszulesen.  
> Das funktioniert zwar, aber wie bekomme ich den Inhalt der SMS  
> in einem String / eine Textvariable.

Was für eine Hardware(UNO/NANO?) nimmst du? Und was bzw. wie funktioniert es?

73...

---

<div class="post-metadata">

**Author:** ![DO3GE](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@DO3GE](https://forum.arduino.cc/u/DO3GE)\
**Post date:** [November 18, 2019, 4:56pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/4 "2019-11-18T16:56:51Z")

</div>

Ich benutze einen UNO.  
Eigentlich funktioniert der Sketch oben wunderbar.  
Die eingehende SMS wird erkannt, gelesen und auf den seriellen Monitor ausgegeben.

Und da beginnt mein Problem. Ich hab da noch ein Verständnisproblem.  
Ich will nun die SMS nicht auf den Monitor, sondern in eine Variable damit ich sie  
weiter verarbeiten kann.

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [November 18, 2019, 5:26pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/5 "2019-11-18T17:26:59Z")

</div>

Dann schau Dir mal an, wie man die Zeichen einer Seriellen Schnittstelle in ein char-Array einliest, z.B. [hier](https://www.wikinger-tommy.de/arduino/tut_zeichenketten.html).  
Du solltest die SMS mit Zeilenvorschub abschließen.

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![HotSystems](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hotsystems/32/219785_2.png) [@HotSystems](https://forum.arduino.cc/u/HotSystems)\
**Post date:** [November 18, 2019, 5:29pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/6 "2019-11-18T17:29:32Z")

</div>

> Ich will nun die SMS nicht auf den Monitor, sondern in eine Variable damit ich sie  
> weiter verarbeiten kann.

Dann sieh dir doch mal in den Beispielen der IDE unter Communication das Beipiel SerialEvent an.

Edit:  
OK....char-Array ist da natürlich klar im Vorteil.  
Aber hier ist schon mal ein mögliches Beipiel.

---

<div class="post-metadata">

**Author:** ![uk1408](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/uk1408/32/241543_2.png) [@uk1408](https://forum.arduino.cc/u/uk1408)\
**Post date:** [November 18, 2019, 6:03pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/7 "2019-11-18T18:03:41Z")

</div>

wie die Vorredner schreiben: Serielle Schnittstelle in einen char-Buffer lesen und dann weiter bearbeiten.  
Ich habe mal was aus einem anderen Projekt rausgenommen.

```cpp
#include <SoftwareSerial.h>

char  Buffer[1000];                                        // Ergebnis vom GSM-Port
String sOK = "OK";                          // Default für GSM_Antwort

//Create software serial object to communicate with SIM800L
SoftwareSerial GSM_Serial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2

bool LeseGSM(int nZeit = 1000, String term = sOK);      // Serielle GSM-Schnittstelle lesen und leeren

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(115200);

  //Begin serial communication with Arduino and SIM800L
  GSM_Serial.begin(19200);

  Serial.println("Initializing...");
  delay(1000);

  GSM_Serial.println("AT");                //Once the handshake test is successful, it will back to OK
  LeseGSM(5000);
  GSM_Serial.println("AT+CMGF=1");        // Configuring TEXT mode
  LeseGSM(5000, "");
  GSM_Serial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  LeseGSM(5000, "");

// um zu sehen was im Netz los ist...
  
  GSM_Serial.println("AT + CSQ");          // RSSI
  LeseGSM(5000, "");
  GSM_Serial.println("AT + COPS ?");      // Provider
  LeseGSM(5000, "");
}

void loop()
{
  if (LeseGSM(5000, "CMT"))
  {
    Serial.println(String(Buffer));
  }
}

// nach  http://miliohm.com/sim800l-arduino-tutorial/
bool LeseGSM(int nZeit, String term = sOK)                        // Serielle Schnittstelle lesen und leeren
{ // nZeit ist Timeout, term wird gesucht
  int  timeout = 0;
  String sBuffer = "leer";

  /* in der Schleife ist ein delay(10) für 10 mSek. Bei nZeit von z.B 1000
    dauert die while-Schleife dann max 1000 * 10 mSek. Die Variable nZeit wird daher
    durch 10 geteilt, dann entspricht der übergebene Wert der Dauer in milliSekunden.
  */

  delay(100);                                              // damit Schnittstelle bereit ist
  while  (!GSM_Serial.available() && timeout < nZeit / 10  )  // Schnittstelle noch nichts zu holen
  { //                                                          und noch nicht Timeout
    delay(10);                                              // 10 mSek.
    timeout++;                                              // Timeout hochzählen
  }
  if (GSM_Serial.available())                              // wenn was von der Schnittstelle kommt
  {
    sBuffer = GSM_Serial.readString();                      // Schnittstelle lesen
    sBuffer.toCharArray(Buffer, sBuffer.length());          // und in globales CHR-Array Buffer kopieren
    if (strstr(Buffer, term.c_str()) != NULL)              // gesuchte(s) Zeichen drin
    {
      Serial.println(String(Buffer));
      return (true);                                        // ok
    }
  }
  return (false);
}

```

Ist quick and dirty, aber müsste dir helfen... Wichtig ist auch das timing, manche Befehle an das SIM800 brauchen etwas Zeit.

---

<div class="post-metadata">

**Author:** ![Serenifly](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Serenifly](https://forum.arduino.cc/u/Serenifly)\
**Post date:** [November 18, 2019, 6:36pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/8 "2019-11-18T18:36:28Z")

</div>

Es ist doch unsinnig ist erst ein String Objekt zu verwenden und das dann in ein Array zu kopieren

1.) Selbst mit Mitteln der Arduino IDE kann man direkt in ein char Array einlesen  
2.) Für reinen Lese-Zugriff kommt man mit c\_str() an das interne Array eines String Objekts  
3.) Es ist auch nicht schwer das per Hand zu machen und Zeichen für Zeichen in ein char Array zu schreiben. Dann geht das auch ohne Blockierung und Timeout

---

<div class="post-metadata">

**Author:** ![uk1408](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/uk1408/32/241543_2.png) [@uk1408](https://forum.arduino.cc/u/uk1408)\
**Post date:** [November 19, 2019, 7:34am UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/9 "2019-11-19T07:34:25Z")

</div>

> Serenifly:  
> Es ist doch unsinnig ist erst ein String Objekt zu verwenden und das dann in ein Array zu kopieren
> 
> 1.) Selbst mit Mitteln der Arduino IDE kann man direkt in ein char Array einlesen  
> 2.) Für reinen Lese-Zugriff kommt man mit c\_str() an das interne Array eines String Objekts  
> 3.) Es ist auch nicht schwer das per Hand zu machen und Zeichen für Zeichen in ein char Array zu schreiben. Dann geht das auch ohne Blockierung und Timeout

Und könntest das etwas näher erläutern? Für manche ist es vielleicht doch schwer....

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [November 19, 2019, 9:37am UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/10 "2019-11-19T09:37:51Z")

</div>

Lies mal den Link in #4.

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 1:47pm UTC](https://forum.arduino.cc/t/problem-beim-sms-lesen-mit-gsm-modul-sim800l/621287/11 "2021-05-06T13:47:45Z")

</div>

Closed on May 6, 2021, 1:47pm UTC


