Loosing info of SMS

Hi,

I am struggling to receive messages on my arduino AT tiny 1634 that is connected to a SIM928A gsm module. I am using serial port 0 to communicate between the arduino and the GSM module. So say I send a SMS to the arduino the first message would be read perfectly, but as soon as I send a second SMS it will only show the first character, and for the third SMS it would only show the second character and so on.

For instance, Say the SMS I send is only the word "YES".

  • The first SMS shows: " REC READ","+phone_number","","16/07/04,14:54:54+08" YES
  • The second SMS shows: only a space
  • The third SMS shows: "
  • The fourth SMS shows: "R
  • The fith SMS shows: "RE
  • And so on.....

Do you perhaps know what could cause this to happen?

Thanks in advance.

arduino_forum.ino.ino (5.1 KB)

well the code is a bit weird but in receiveSMS you do this:

      if (Serial.available() > 0) {
        sms_text[x] = Serial.read();
        x++;
      }

You have no indicator that you have received the end of the message... Serial.available might return 0 at some point because the buffer is empty because you read super fast in this loop but your incoming buffer can only receive at ~1000 chars per second --> may be there are still some stuff in transit but you miss it...
You should implement a time out, like if you have something arriving, then read what's coming but wait for for 5 seconds before deciding it's the end of the input string.

Wondering also you are fine if receiveSMS will be stuck in an infinite loop if you don't send "Ja", "Nee" or "Change ID"?

When you get the command response, you only read up to the response you are looking for. There are still characters to be read.

Instead, read the entire line (up to the newline characters, '\r' and/or '\n'). Then look for the response string.

Otherwise, the remaining characters of the response will be loaded into the sms_text variable. And you should probably have a timeout in the receiveSMS do-while loop.

And learn how to indent. :stuck_out_tongue: You can press control-T in the IDE editor and it will auto-format the code for you.

Cheers,
/dev

Thanks for the reply guys!

Ok so what I have done is to put a time-out delay in the do-while loop to insure I don't loose any info, however the problem persist. Don't know if you meant to insert a simple delay as a time-out?

But whats bothering me is the fact that from the second SMS and on, the arduino each time sends one character more than with the prevouis SMS.

I am going to improve the code, but for know I only want to be able to send a SMS to the arduino and then the arduino should be able to read the SMS and reply with the same SMS. For instance if I send "JA" it should just reply with the word "JA". So for know I am insuring it won't get stuck in that infinite loop.

I think I have fixed it, but there is still some concerns.

Ok so what I've done is to clean the array in which I store my incoming message before I write to it. Then I also have to put in a delay in the do-while loop otherwise my gsm module connected to the arduino shuts down.

Not sure why it shuts down, but if someone knows please let me know. With the current code it takes almost 5 minutes from the moment the gsm modules receives the sms to the moment I receive a SMS back on my phone.

arduino_forum.ino (4.61 KB)

Maybe post your updated code.

Note that delay and timeout are two totally different things.

PS
South African by any chance?

I attached the updated code in the previous post. If you perhaps see something that may cause the delay in sending the received SMS please let me know.

Yes Sterretje, you?

Dutch, living in South Africa for the last 15 years (Jo'burg area, Roodepoort).