Issue with AT+CIPGSMLOC=1,1

Good day, all!

I actually experiment a issue because the command

AT+CIPGSMLOC=1,1

return me an error response, when I start my App but only the 3 first GSMLOC requests.

I wundering if I correctly open the GPRS, at the good time

Thank for reading my post and I will try to give you a good explication.

My GPRS/GSM module is a SIM808

I am using my module to

  • Send and receive SMS
  • Receive call to listen what happen around the module
  • Get GPS location
  • If no GPS, get GSM Location
  • Send coordinate to a remote server
  • Write / read in SD card the APN and the coordinate which have not been sent
  • SOS button (interrupt)

All works excepted AT+CIPGSMLOC=1,1 when I start my App and then it work.

Note, I open my GPRS in the setup() and I wundering if I should open the GPRS before I request a GSMLOC or when I send the data with HTTP to the remote server, and immediately close the GPRS connection.

here is my actiion
In setup()

Wait 3 sec.
Initializing FONA....
Attempting to open comm with ATs
 ---> AT
 <--- AT
 ---> ATE0
 <--- ATE0
 ---> ATE0
 <--- OK
 ---> AT+CVHU=0
 <--- OK
 ---> ATI
 <--- SIM808 R14.18
OK

+CPIN: READY

FONA 808 (v2) is OK
 ---> AT+CPIN?
 <--- +CPIN: READY
SIM card is ready

 ---> AT+CREG?
 <--- +CREG: 0,2
NS: Not registered (searching)
 ---> AT+CREG?
 <--- +CREG: 0,2
NS: Not registered (searching)
 ---> AT+CREG?
 <--- +CREG: 0,2
NS: Not registered (searching)
 ---> AT+CREG?
 <--- +CREG: 0,1
NS: Home

 ---> AT+COPS?
 <--- +COPS: 0,0,"Orange"

Turn on GPS
 ---> AT+CGNSPWR?
 <--- +CGNSPWR: 0
 ---> AT+CGNSPWR=1
 <--- OK

ENABLE GPRS AND CHECK enableGPRSAndCheck(2)
 ---> AT+CSQ
 <--- +CSQ: 14,0

Check SAPBR (Bearer): 
 ---> AT+SAPBR=2,1
 <--- +SAPBR: 1,3,"0.0.0.0"
 Bearer status: 3, Closed

Enabling GPRS
 ---> AT+CIPSHUT
 <--- SHUT OK
 ---> AT+CGATT=1
 <--- OK
 ---> AT+SAPBR=3,1,"CONTYPE","GPRS"
 <--- OK
 ---> AT+SAPBR=3,1,"APN","click"
 <--- OK
 ---> AT+CSTT="click","",""
 <--- OK
 ---> AT+SAPBR=3,1,"USER",""
 <--- OK
 ---> AT+SAPBR=3,1,"PWD",""
 <--- OK
 ---> AT+SAPBR=1,1
 <--- OK
 ---> AT+CIICR
 <--- OK

Sync UTC time. 5 attends.
 ---> AT+CNTPCID=1
 <--- OK
 ---> AT+CNTP
 <--- OK
NTP Service response error
GPRS not enable. Check APN.
 ---> AT+CNTPCID=1
 <--- OK
 ---> AT+CNTP
 <--- OK
Sync NTP time OK
GPRS enabled


Running since: 43 sec.

 ---> AT+CPBS?
 <--- +CPBS: "SM",3,250

// Requesting the monnay ballance
 ---> AT+CUSD=1
 <--- OK
 ---> AT+CUSD=1,"#121#"
 <--- OK
 USSD Reply (36 bytes):Votre solde actuel est de CHF 16.62.

// Check battery level
 ---> AT+CBC
 <--- +CBC: 0,100,4222

// Request time
 ---> AT+CCLK?
 <--- +CCLK: "16/08/24,00:54:53+08"

Time: "16/08/24,00:54:53+08"

At the end of setup, all work fine. Now the loop() starts and observe the 4 AT+CIPGSMLOC=1,1 response:

If you observe well, the first and second time time, AT+CIPGSMLOC return that response:

<--- +CIPGSMLOC: 603
<--- +CIPGSMLOC: 603

(DNS error)
The third time, the response is

<--- +CUSD: 4

here is the sequence in loop()

 ---> AT
 <--- OK

Running since: 0 sec.
// Check quality of signal
 ---> AT+CSQ
 <--- +CSQ: 13,0

// Check network
 ---> AT+CREG?
 <--- +CREG: 0,1
Network status: Home

Get timestamp (NTP)
 ---> AT+CCLK?
 <--- +CCLK: "16/08/24,00:54:55+08"

Check call status
 ---> AT+CPAS
 <--- +CPAS: 0
 > Line is READY

Checking unsent SOS in SD card
--------------------------
Nb of Files: 0
/SOS/ does not exist

Check call status
 ---> AT+CPAS
 <--- +CPAS: 0
 > Line is READY

REQUEST GPS AND SEND
* * * * * * * * * * * * * *
Running since: 2 sec.
// Check quality of signal
 ---> AT+CSQ
 <--- +CSQ: 13,0

Check GPRS
--------------------------
Is Attached: ---> AT+CGATT?
 <--- +CGATT: 1 // OK

 ---> AT+SAPBR=2,1
 <--- +SAPBR: 1,1,"10.176.175.151"
 Bearer status: 1, Connected (CHECK IF NEED NTPSYNC)

Running since: 4 sec.

Starting Geolocalisation
--------------------------

1/5 attend to get GPS
Get coordinate ---> AT+CGNSINF
 <--- +CGNSINF: 1,0,19800106000016.000,,,,0.00,0.0,0,,,,,,0,0,,,,,
// The GPS location is not valid, then it look for GSM location (triangulation)

Check SAPBR (Bearer): 
 ---> AT+SAPBR=2,1
 <--- +SAPBR: 1,1,"10.176.175.151"
 Bearer status: 1, Connected (CHECK IF NEED NTPSYNC)

// Read DNS
 ---> AT+CDNSCFG?
 <--- PrimaryDns: 10.9.11.21

Getting GSMLOC
 ---> AT+CIPGSMLOC=1,1
 <--- +CIPGSMLOC: 603
GSMLOC Failed!

Could not get GSM or GPS coordinates


2/5 attend to get GPS

Get coordinate ---> AT+CGNSINF
 <--- +CGNSINF: 1,0,19800106000032.000,,,,0.00,0.0,0,,,,,,0,0,,,,,
DEBUG: GPS Status: 1
// GPS not valide, then it ask for the second time GSM Loc

DEBUG: Check SAPBR (Bearer): 
 ---> AT+SAPBR=2,1
 <--- +SAPBR: 1,1,"10.176.175.151"
 Bearer status: 1, Connected (CHECK IF NEED NTPSYNC)

// Read again the DNS
 ---> AT+CDNSCFG?
 <--- PrimaryDns: 10.9.11.21

Getting GSMLOC
 ---> AT+CIPGSMLOC=1,1
 <--- +CIPGSMLOC: 603
GSMLOC Failed!

Could not get GSM or GPS coordinates


3/5 attend to get GPS

Get coordinate ---> AT+CGNSINF
 <--- +CGNSINF: 1,0,19800106000049.000,,,,0.00,0.0,0,,,,,,0,0,,,,,
DEBUG: GPS Status: 1
// GPS not valid, then it ask GSMLOC for the third time

DEBUG: Check SAPBR (Bearer): 
 ---> AT+SAPBR=2,1
 <--- +SAPBR: 1,1,"10.176.175.151"
 Bearer status: 1, Connected (CHECK IF NEED NTPSYNC)
// DNS
 ---> AT+CDNSCFG?
 <--- PrimaryDns: 10.9.11.21

Getting GSMLOC
 ---> AT+CIPGSMLOC=1,1
 <--- +CUSD: 4

GSMLOC Failed!

// THEN FROM NOW, ALL ANSWER ARE EMPTY UNTIL THE 4TH GSMLOC REQUEST

DEBUG: Check SAPBR (Bearer): 
 ---> AT+SAPBR=2,1
 <--- 
 Bearer status: 0, Connecting

Could not get GSM or GPS coordinates

4/5 attend to get GPS

Get coordinate ---> AT+CGNSINF
 <--- 
DEBUG: GPS Status: -1
 ---> AT
 <--- 

// IT RECEIVE THE GSMLOC RESPONSE NOW!!!! STRANGE
DEBUG: Check SAPBR (Bearer): 
 ---> AT+SAPBR=2,1
 <--- +CIPGSMLOC: 0,6.141064,46.219772,2016/08/24,00:55:39
 Bearer status: 0, Connecting

 ---> AT+CDNSCFG?
 <--- PrimaryDns: 10.9.11.21


// NOW THE GSMLOC RESPONSE IS CORRECT
Getting GSMLOC
 ---> AT+CIPGSMLOC=1,1
 <--- +CIPGSMLOC: 0,6.141064,46.219772,2016/08/24,00:55:40

If you observe, after the 3rd GSMLOC attend, all response are empty and the program look like a bit creasy :o).
At the 4th GSMLOC request, the response is correct and from that step, the program works well at each loop() interraction.
From that point all command return a correct andswer and AT+CIPGSMLOC=1,1 returns always a correct answer.

I do not understang why AT+CIPGSMLOC=1,1 need to be called 4 times to have the programm running correctely and why AT+CIPGSMLOC=1,1 make troubles to the following command.

I also open the GPRS connection at stup() and it remaind always open.

Enabling GPRS
 ---> AT+CIPSHUT
 <--- SHUT OK
 ---> AT+CGATT=1
 <--- OK
 ---> AT+SAPBR=3,1,"CONTYPE","GPRS"
 <--- OK
 ---> AT+SAPBR=3,1,"APN","click"
 <--- OK
 ---> AT+CSTT="click","",""
 <--- OK
 ---> AT+SAPBR=3,1,"USER",""
 <--- OK
 ---> AT+SAPBR=3,1,"PWD",""
 <--- OK
 ---> AT+SAPBR=1,1
 <--- OK
 ---> AT+CIICR
 <--- OK

That is a good idea?
I wundering if I should open and close it only when I need it. For exemple with AT+CIPGSMLOC and HTTP rquest?

Your help and suggestion will help me a lot, and thank for reading my codes
I hope I provided good information

Cheers

Is there a way to remove / avoid / cancel all Unsolicited Result code?

Also note, each time a command is lunched, the buffer is cleanned

uint16_t timeoutloop = 0;
    while (timeoutloop++ < 40) {
        while(available()) {
            read();
            timeoutloop = 0;  // If char was received reset the timer
        }
        delay(1);
    }

I'm not sure but you probably just need a delay at the start before starting to get location because it takes time to initialize the gsm module
I had the same problem with sim808 gps/gsm/gprs module .
all I needed was a delay at the start until the module gets power then initialize .