GSM Location service of SIM800x modules and its work with Yandex.Locator API



Google, unfortunately for many users of GSM modules, blocked and transferred to a paid basis an API 2-3 months ago for determining the location by coordinates of the cell towers visible by the module. Because of this, the functionality of the AT + CIPGSMLOC team has ceased to work on the modules of the SIM800 series manufactured by SIMCom Wireless Solutions . In this article I will tell you how to solve the problem by using a similar service provided by Yandex - Yandex.Locator .

We’ll omit how Yandex receives the coordinates of cell towers, the main thing is that we can use this free service and get the following data: Latitude, Longitude, Altitude, as well as the approximate error for each parameter. The main goal of the article is to give a small tutorial on the quick transition to the API from Yandex, instead of the no longer available service from Google.

Below, as an example, we will only obtain the latitude and longitude of the location of the module.

So let's get started


First you need to read the user agreement, located at: yandex.ru/legal/locator_api . Particular attention should be paid to clause 3.6. of this user agreement, which states that Yandex reserves the right to change / correct or update the Yandex.Locator API at any time, without prior notice .

Go to yandex.ru/dev/locator/keys/get and add your previously created Yandex account to the development group. These actions will allow you to get a key to access this service.


Write down or otherwise save the received key.

After performing these steps, you will get access to the page yandex.ru/dev/locator/doc/dg/api/geolocation-api-docpage where basic information about the mechanism of the Yandex.Locator service is provided.

To generate an XML-request in cURL format for Yandex.Locator services, you will need to obtain information on the “visible” module cell towers:

  • countrycode - country code
  • operatorid - mobile network code
  • cellid - cell id
  • lac - location code

This information can be obtained from the module by sending the command 'AT + CNETSCAN'.

Information received from the module
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:59,Cellid:2105,Arfcn:96,Lac:1E9E,Bsic:31<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:54,Cellid:2107,Arfcn:18,Lac:1E9E,Bsic:3A<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:45,Cellid:10A9,Arfcn:97,Lac:1E9E,Bsic:11<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:41,Cellid:2108,Arfcn:814,Lac:1E9E,Bsic:1F<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:43,Cellid:5100,Arfcn:13,Lac:1E9E,Bsic:2B<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:39,Cellid:5102,Arfcn:839,Lac:1E9E,Bsic:1A<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:38,Cellid:2106,Arfcn:104,Lac:1E9E,Bsic:0A<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:37,Cellid:0FE7,Arfcn:12,Lac:1E9E,Bsic:24<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:44,Cellid:14C8,Arfcn:91,Lac:1E9E,Bsic:24<CR><LF>
Operator:"MegaFon",MCC:250,MNC:02,Rxlev:37,Cellid:04B3,Arfcn:105,Lac:1E9E,Bsic:3A<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:47,Cellid:29A0,Arfcn:70,Lac:39BA,Bsic:09<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:43,Cellid:0FDD,Arfcn:590,Lac:39BA,Bsic:09<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:44,Cellid:29A1,Arfcn:84,Lac:39BA,Bsic:10<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:40,Cellid:8F95,Arfcn:81,Lac:39BA,Bsic:03<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:43,Cellid:0FDF,Arfcn:855,Lac:39BA,Bsic:24<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:37,Cellid:299C,Arfcn:851,Lac:39BA,Bsic:17<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:37,Cellid:0FDE,Arfcn:852,Lac:39BA,Bsic:1B<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:35,Cellid:299F,Arfcn:72,Lac:39BA,Bsic:10<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:33,Cellid:28A5,Arfcn:66,Lac:396D,Bsic:25<CR><LF>
Operator:"Bee Line GSM",MCC:250,MNC:99,Rxlev:33,Cellid:2A8F,Arfcn:71,Lac:39BA,Bsic:23<CR><LF>
Operator:"MOTIV",MCC:250,MNC:20,Rxlev:46,Cellid:39D2,Arfcn:865,Lac:4D0D,Bsic:14<CR><LF>
Operator:"MOTIV",MCC:250,MNC:20,Rxlev:36,Cellid:09EE,Arfcn:866,Lac:4D0D,Bsic:25<CR><LF>
Operator:"MOTIV",MCC:250,MNC:20,Rxlev:28,Cellid:09ED,Arfcn:869,Lac:4D0D,Bsic:22<CR><LF>
Operator:"MOTIV",MCC:250,MNC:20,Rxlev:28,Cellid:09EF,Arfcn:861,Lac:4D0D,Bsic:17<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:66,Cellid:58FE,Arfcn:1021,Lac:00EC,Bsic:0A<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:50,Cellid:58FD,Arfcn:1016,Lac:00EC,Bsic:08<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:49,Cellid:58FF,Arfcn:1023,Lac:00EC,Bsic:09<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:46,Cellid:F93B,Arfcn:59,Lac:00EC,Bsic:20<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:50,Cellid:381B,Arfcn:1020,Lac:00EC,Bsic:0A<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:37,Cellid:3819,Arfcn:42,Lac:00EC,Bsic:08<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:34,Cellid:4C0F,Arfcn:43,Lac:00EC,Bsic:0A<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:33,Cellid:0817,Arfcn:26,Lac:00EC,Bsic:27<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:34,Cellid:3A5D,Arfcn:1017,Lac:00E9,Bsic:34<CR><LF>
Operator:"MTS",MCC:250,MNC:01,Rxlev:33,Cellid:3D05,Arfcn:1018,Lac:00EC,Bsic:1F<CR><LF>

It is important to note that in the future it will be necessary to convert the data from the module's answer about Cellid and Lac from hexadecimal to decimal.

Now we need to generate XML data to access the Yandex server, which, in the future, will be combined into one element.

Data table
xml=<ya_lbs_request><common><version>1.0</version><api_key>
...88-
</api_key></common>
<gsm_cells>
<cell><countrycode>
250
(MCC)
</countrycode><operatorid>
2
(MNC)
</operatorid><cellid>
8453
Cellid 16 10 ( — 2105)
</cellid><lac>
7838
Lac , 16 10 ( – 1E9E)
</lac></cell>
...
, cell -
</gsm_cells>
<ip><address_v4>
10.137.92.60
IP GPRS , ‘AT+SAPBR=2,1’ – .
</address_v4></ip></ya_lbs_request>


Thus, an XML message with the length of 1304 characters of the following form will be generated:

Message
xml=<ya_lbs_request><common><version>1.0</version><api_key>{    }</api_key></common><gsm_cells><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>8453</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>8455</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>4265</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>8456</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>20736</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>20738</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>8454</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>4071</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>5320</cellid><lac>7838</lac></cell><cell><countrycode>250</countrycode><operatorid>2</operatorid><cellid>1203</cellid><lac>7838</lac></cell></gsm_cells><ip><address_v4>10.137.92.60</address_v4></ip></ya_lbs_request>


This message is based on the data on the cell towers of the Megafon operator, it can be supplemented with data including on other towers visible by the module received by the command 'AT + CNETSCAN' to increase the reliability of the issued coordinates.

Working with the module and obtaining current coordinates


AT-log of work with the module
>AT+SAPBR=3,1,”Contype”,”GPRS” //     
<OK
>AT+SAPBR=3,1,”APN”,”internet” //  APN 
<OK
>AT+SAPBR=1,1 //    GPRS 
<OK //  
>AT+SAPBR=2,1 //   IP     
<+SAPBR: 1,1,”10.137.92.60” //  IP     XML-
<
<OK
>AT+HTTPINIT
<OK
>AT+HTTPPARA=”CID”,1
<OK
>AT+HTTPPARA=”URL”,”http://api.lbs.yandex.net/geolocation”
<OK
>AT+HTTPDATA=1304,10000 //   –   XML-
<DOWNLOAD //    XML-
< //    XML-
<OK
>AT+HTTPACTION=1
<OK
<
<+HTTPACTION: 1,200,303 // 200 –  , 303 –  303  
>AT+HTTPREAD=81,10
<+HTTPREAD: 10
<60.0330963 //     
<OK
>AT+HTTPREAD=116,10
<+HTTPREAD: 10
<30.2484303 //     
>AT+HTTPTERM
<OK

Thus, we got the current coordinates of the module: 60.0330963, 30.2484304.
With the increase in the number of data sent by cell towers, the accuracy of location determination will proportionally increase.

More detailed information on the content of the response from the Yandex.Locator service and the selection of the data you need can be found at: yandex.ru/dev/locator/doc/dg/api/xml-reply-docpage , in the API-> XML-> Reply section

Conclusion


I hope this material will be a good help to developers. Ready to answer your questions in the comments.

All Articles