Sim800l: how to know network state reliably

1.7k Views Asked by At

In Sim800L AT-Commands Guide there are a lot of different status commands, that should tell, what state does is have.

For example:

AT+CPAS - check if device is ready
AT+CGREG? - check registration status in network
AT+CGATT? - check if device "attached to network"
AT+CSQ - get signal level

But, in some cases, answers to this commands could be an "ERROR", or no answer at all.

I need a reliable and fast method to know is device connected to network, or it's already in GPRS mode, and for now I came to use blinking LED on Sim800L to detect it's state.

LED has three blinking frequencies:

  1. Fast blinking - GPRS connection is active
  2. Medium speed of blinking - Network connection is not established yet
  3. Slow blinging - Device is connected to network (but not the GPRS)

I can use photodiode and "read" blinging of LED, or I can wire LED's power pin to analog pin of Arduino, and read it's voltage. Next, I can count how fast LED is blinking, and determine, which state Sim800L in.

But how do I get this level of reliability without using such a crutch?

1

There are 1 best solutions below

1
On

Given fast means 1 sec you could send an AT command e.g. five times and take 3 non error responses as a valid result. See pseudo code

uint8_t  errorCount = 0;
for (uint8_t i=0;i<5;i++){
 .... send AT command ... 
if (response == "error")  errorCount++;
if (errorCount >=3) errorHandling();
}
 ... process successful AT command ...

or your HW approach with LED to analog pin