We decided the problem about 10 years ago.
You need to process unsolicited +CREG and try to ask for current registration. These are some variations CREG:
//+CREG: 1,“1111”,“2222” – unsolicited home cell info
//+CREG: 5,“1111”,“2222” – unsolicited roaming cell info
//+CREG: 2,1,"1111","2222" -- home cell /answer
//+CREG: 2,5,"1111","2222" -- roaming cell /answer
//+CREG: 2,0 -- not register, not search /answer
//+CREG: 2,2 -- not register, search /answer
//+CREG: 2,1,"6981","708D" -- normal reg / answer
//+CREG: 2,5,"XXXX","XXXX" -- roaming reg /answer
But you can not rely on the home network flag, it is often “home” in the guest networks…
How should we resolve this inaccuracy? If you ask your SIM card IMSI, you will be able to compare the number of first digits of the code with the first digits of the current registered operator network.
This is a very simplified algorithm:
1> AT+CIMI
25503xxxxxxxxxx
2> AT+COPS?
+COPS: 0,2,“25503”
3> Compare “25503” with 25503xxxxxxxxxx for length of COPS respond. So in this example we have Ukraine, Kyivstar GSM network and the same SIM card.
In case of compare match we are in the HOME network and will use home connection rules.
In case of compare mismatch we have a quasi-home network. Do not trust to CREG data and use roaming connection rules.
4> As a side effect you know a SIM card IMSI and will select GPRS access point from local database.
This algorithm help’s to select home network with any type of GSM equipment. Tested on three generations.
You only need stable respond to reading IMSI and COPS request. And do not forget to use a “magic switch” of the modem’s power - much more interesting events happens even in the home network. Just like in the russian song “Do not cry, do not be afraid, do not call…”
I hope this will help you. Enjoy! 