Pregunta

I'm doing some experiments with Arduino+Siemens TC35 GSM module and I would like to be able to read an SMS that I send to this device.

I have assembled my device following more or less this scheme:

enter image description here

with the difference that I don't use a buzzer nor a relay, just an LCD display. You can see the full picture here:

enter image description here

The scheme should work, because for example I have been able to send an SMS from Arduino to my mobile phone, but I'm having some problems parsing the SMS I send to my Arduino.

(note: I will hide my number substituting some numbers with ***)

I initialize the GSM module like this:

mySerial.print("AT+CMGF=1\r\n");

and I try to read my SMS like this:

void readSMS()
{
  mySerial.print("AT+CMGR=6\r\n");
  delay(1000);

  char c;

  while (mySerial.available()>0){
     c = (char)mySerial.read(); 
     Serial.print(c);
  }
}

but I always get a truncated SMS. This is what I see in my Serial monitor:

AT+CMGF=1
OK
AT+CMGR=6
+CMGR: "REC READ","AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6
+CMGR: "REC READ","+4475********",,"14/04/25,21:08:AT+CMGR=6

what's wrong with my code?

Thank you so much for any help.

p.s: also other commands that are supposed to work (for example the one to delete all SMS: AT+CMGD=1,4) don't work at all and give me error.

p.p.s: I wish I could use the GSM.h library that is available for Arduino, but I guess it's only compatible with the original Arduino GSM Shield.

¿Fue útil?

Solución

I'm not an Arduino expert in any capacity, so there may be better ways to do this in the API, but I'd try something like this (delays can probably be lowered)

void readSMS()
{
  mySerial.print("AT+CMGR=6\r\n");     // Send request

  int count = 5;                       // Number of 100ms intervals before 
                                       // assuming there is no more data
  while(count-- != 0) {                // Loop until count = 0

    delay(100);                        // Delay 100ms

    while (mySerial.available() > 0){  // If there is data, read it and reset
       c = (char)mySerial.read();      // the counter, otherwise go try again
       Serial.print(c);
       count = 5;        
    }
  }
}

Another - probably better - option would be to just loop without a delay until you get a complete answer. That of course assumes that you know what to look for (<cr><lf>OK<cr><lf> would seem to be the case here, but I'm too weak on the Hayes spec to be sure)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top