Problem with SIM800L GSM Module Causing Crash / Lock Up


I have a project that uses a SIM800L GSM Module to receive commands and also to send data back home. Everything works 99.9% of the time but occasionally, the SIM800L will cause the whole system to lock up and only a reset will put things back right.

My project spends most of its time sleeping in Low Power Sleep Mode but wakes up on the hour to power up the GSM to listen for SMS messages. It’s then that the problem happens. It can work for hours or days without issue and then suddenly everything locks up when it comes to listening for an SMS message.

I believe I’ve narrowed the problem down to one of two possible causes.

  1. This is what I think is most likely… The GSM Module sometimes cannot register to the network when it wakes up and that causes some sort of problem in the code which has not been handled correctly.

  2. My network provider is fond of sending a dozen spam SMS messages per week advertising the next great package. Perhaps the code doesn’t know how to handle / reject them properly and that’s causing an issue somewhere?

The code I used to receive and process SMS messages was borrowed from the internet and adapted for my needs but I’m not entirely confident of it.

The project should wake up, check for the first SMS message stored on the SIM and if that SMS comes from the master number, process it. Otherwise, ignore the message and delete it and then go back to sleep again.

Somewhere along the lines, something is going wrong and bringing the process to a grinding halt.

The functions used are attached below.

Any help greatly received!

Code.txt (10.7 KB)

In order to exclude the second case save the undesirables sms to the sim card and read them with manual AT command after crash.

Is this line of code necessary?c = c;

Please attach your complete code. First suspect (for me) is the use of String (capital S).

Which Arduino are you using?

Re your carrier spam or old unwanted incoming messages...
After modem initialisation, i suck any incoming messages dry before going into the main loop.

BTW, i don’t use the modem’s internal text storage, I parse & process every message ‘live’ to avoid this in any other case.
I also keep an eye open for overlength messages, and/or carrier notifcations (low credit, expire etc) so they can be handled appropriately.

Worst case, keep an eye on all the other possibilities like signal strength, cell registration etc so you can cycle the modem or whole application as needed.
I have many modems in the field, and so far zero ‘locked up’ over a couple of years. (Touch wood)