SIM800L GSM module bloks after receiving several SMS.

Hello,

I’ve used SIM800L cheap module for arduino project. System is controled via SMS, and I have a huge problem.

After sending 2 or more SMS to Arduino system kinda blocks. Here’s whats happening:

After sending 2 or more SMS instantly SIM module block and last message goes stuck in SIM memory and every loop the same comand is given (according to last SMS)

This is a huge problem, did anyone has similar problem?

Is there a solution for this?

Have you read and delete the received SMSes? The storage for the SMS is limited. Have you checked how many SMS are stored in the module? If possible you should read out a received SMS and delete it immediately afterwards.

pylon: Have you read and delete the received SMSes? The storage for the SMS is limited. Have you checked how many SMS are stored in the module? If possible you should read out a received SMS and delete it immediately afterwards.

@pylon I'm using SIM900IDE library and in the library code there is a line that delete all messages after reading, and that's not the problem. When I send the comand via SMS and everything is working OK, arduino reads message, do the comand given and than delete the message. But for exapmle if there is no coverage and I send 3 SMS messages, and when the sim module receive all 3 SMS at the same time it goes stuck and it's always sending one message to arduino all over again. And then arduino is doing the same thing in every loop. You get the problem? Is it prossible that the sim module isn't good enough or you think it's something in the code thats wrong?

But for exapmle if there is no coverage and I send 3 SMS messages, and when the sim module receive all 3 SMS at the same time it goes stuck and it's always sending one message to arduino all over again.

The module might get all three messages at once. The Arduino (should) only ask(s) it for one at a time.

and it's always sending one message to arduino all over again. And then arduino is doing the same thing in every loop. You get the problem? Is it prossible that the sim module isn't good enough or you think it's something in the code thats wrong?

In your code or in the library? Yes.

PaulS: The module might get all three messages at once. The Arduino (should) only ask(s) it for one at a time.

How do I get Arduino to ask only for one message? Do you want me to post the code that process the SMS?

PaulS: In your code or in the library? Yes.

In the library, in code there is no such command. Should I add it to the code?

Do you want me to post the code that process the SMS?

No. You need to post ALL of the code.

In the library, in code there is no such command.

No such command as what? The library should have a method to return the number of messages, to return one of the messages, and to delete one, or all, of the messages.

Here is the code, some part of it is in Serbian, but I think you'll find what you need.

As you can see, in code I didnt implement the command for deleting all the messages.

I have another question related to SIM module but, I'll post it later.

Thank you for trying to help me!

#include "SIM900.h"
#include "SIM900.h"

Maybe you need to include this file a few more times.

      //Read if there are messages on SIM card and print them.
      if(gsm.readSMS(smsbuffer, 160, n, 20))

How many messages does the method read? Without a link to the library, the only way I have of knowing is to ask you.

As you can see, in code I didnt implement the command for deleting all the messages.

So, it's no wonder why, once a message arrives, the Arduino keeps doing the same thing over and over.

Once you process an SMS, you need to delete it.

Here is the link to the library: https://1drv.ms/u/s!AjaM1viyaKZlk27z0Xstlu4mmQuv

PaulS: ```

include "SIM900.h"

include "SIM900.h"



Maybe you need to include this file a few more times.

I've accidentaly copied it twice when copying the code :)

PaulS: ```

include "SIM900.h"

include "SIM900.h"



Maybe you need to include this file a few more times.



      //Read if there are messages on SIM card and print them.       if(gsm.readSMS(smsbuffer, 160, n, 20)) ```

How many messages does the method read? Without a link to the library, the only way I have of knowing is to ask you.

Please check the library in the link above. Correct me if I'm wrong but I think that the library should delete the message after processing it?

Please check the library in the link above.

I can't. That location is NOT where you got the library. Post a link, AS A LINK (use the 12th icon from the left), to that location.

Correct me if I'm wrong but I think that the library sould delete the message after procesing it?

I don't think that that is a reasonable assumption. My phone doesn't delete text messages just because I read them. I would be surprised, and pissed, if the library did that.

PaulS:
I can’t. That location is NOT where you got the library. Post a link, AS A LINK (use the 12th icon from the left), to that location.

Sorry for the mistake, here is the link for the library:

PaulS:
I don’t think that that is a reasonable assumption. My phone doesn’t delete text messages just because I read them. I would be surprised, and pissed, if the library did that.

Here’s the code from the sms.h file from the library for deleting the message after processing it:

/**********************************************************
Method deletes SMS from the specified SMS position

position:     SMS position <1..20>

return:
        ERROR ret. val:
        ---------------
        -1 - comm. line to the GSM module is not free
        -2 - GSM module didn't answer in timeout
        -3 - position must be > 0

        OK ret val:
        -----------
        0 - SMS was not deleted
        1 - SMS was deleted
**********************************************************/
char SMSGSM::DeleteSMS(byte position)
{
     char ret_val = -1;

     if (position == 0) return (-3);
     if (CLS_FREE != gsm.GetCommLineStatus()) return (ret_val);
     gsm.SetCommLineStatus(CLS_ATCMD);
     ret_val = 0; // not deleted yet

     //send "AT+CMGD=XY" - where XY = position
     gsm.SimpleWrite(F("AT+CMGD="));
     gsm.SimpleWriteln((int)position);


     // 5000 msec. for initial comm tmout
     // 20 msec. for inter character timeout
     switch (gsm.WaitResp(5000, 50, "OK")) {
     case RX_TMOUT_ERR:
          // response was not received in specific time
          ret_val = -2;
          break;

     case RX_FINISHED_STR_RECV:
          // OK was received => SMS deleted
          ret_val = 1;
          break;

     case RX_FINISHED_STR_NOT_RECV:
          // other response: e.g. ERROR => SMS was not deleted
          ret_val = 0;
          break;
     }

     gsm.SetCommLineStatus(CLS_FREE);
     return (ret_val);
}

Here's the code from the sms.h file from the library for deleting the message after processing it:

So, where do you call that method? The fact that the method exists is not enough to make it do anything.

It also appears that you should be calling IsSMSPresent() and GetSMS() (not readSMS()).

Paul,

sorry for confusion. I look more into GSM library and my code. I do not call DeleteSMS(), GetSMS() and isSMSPresent() functions.

I am just using readSMS() which is doing all of that together:

boolean SIMCOM900::readSMS(char* msg, int msglength, char* number, int nlength)
{
  long index;
  _tf.setTimeout(_GSM_DATA_TOUT_);
  _cell << "AT+CMGL=\"REC UNREAD\",1" << endl;
  if(_tf.find("+CMGL: ")) // if sms present
  {
    index=_tf.getValue();
    _tf.getString("\"+", "\"", number, nlength);
    _tf.getString("\n", "\nOK", msg, msglength);  // get sms
    _cell << "AT+CMGD=" << index << endl;    / delete sms
    _tf.find("OK");
    return true;
  };
  return false;
};

Is there a benefit to use isSMSPresent(), getSMS() and deleteSMS() instead this function? Anyway I will try if that can resolve my problem with receiving 3 SMS at the same time.

Is there a benefit to use isSMSPresent(), getSMS() and deleteSMS() instead this function?

I would think that the fact that the function is flagged as deprecated would be sufficient.

I would also think that you could have tried using the three methods, instead of the one, and determined whether or not there was an improvement in the overall process, in less time than it would have taken to argue that the one function does it all.

Thanks, I didn’t notice that, because I have downloaded library before deprecation.

I will get newest version and try to use methods isSMSPresent(), getSMS() and deleteSMS().

Let you know if this solved my problem.

Paul, i would like to thank you for helping me, now everyting is working more than fine. I've used the metods you suggested and none of the problems occurs anymore. Thank you again for your time and help! Cheers!

none of the problems occurs anymore.

Excellent news. Thanks for following up.