Hi, am interfacing gps tracker TK106 with our online platform. The data we get from gps device is in this format


Instractions form this site explains the variours data sets in the string above, for example the first 11 digits


is the device's programmable ID ,used in placed of the IMEI number.The problem is, i need to find a way to dynamically seperate these digits automatically as they are sent by the gps device, so we can plot location of fleets in real time.



is a hex # (odometer reading), this have to be converted from Hex to decimal. Example:

Conversion Process:
Hex to decimal: 000024DE == 9438
Divide by 100 : 9438 == 94.38
Odometer reads: 94.38 KM

it seems abit easy to seperate and convert using pathon, but my core language is PHP. From my research, using PHP substring seems to be the way forward, but i just can't bring my head around it. Thx for helping out...

Edited by accra

3 Years
Discussion Span
Last Post by accra

Using substr is certainly possible if the parts are fixed in size (appears so from glancing over the docs). So what is the problem you have with substr?


The problem is this, i need to separate this string below


like this one here:

0 66677788899 BP050000 66677788899 140815 A 0533.8206N 00009.7045W 000.0 165936 157.62 00000000 L0000F51C

then save it to a txt file or mysql, then i can do the convertion, but am abit confused how to do this.

An other thing that worry me is this: some digets in the string may change due to lat,lon,speed etc. This make it difficult to simply search for a constant and place a seperator between them...

If any one have a sample code to draw inspiration from, i will be greatful...

Edited by accra


Thanks for the help, i put this together though.

include "inc/db.php";

$data = '013666666666BP05000013666666666110925A1234.5678N01234.5678W000.002033490.00000000000L000024DE';

echo $imei_device = substr($data, 1, 11).'--';
echo $unkn = substr($data, 12, 8).'--';
echo $imei_device_2 = substr($data, 1, 11).'--';
echo $ymd = substr($data, 31, 6).'--';
echo $accurate = substr($data, 37, 1).'--';
echo $lat = substr($data, 38, 10).'--';
echo $lon = substr($data, 48, 11).'--';
echo $speed_kph = substr($data, 59, 5).'--';
echo $time_gmt = substr($data, 64, 6).'--';
echo $c_deg = substr($data, 70, 6).'--';
echo $device_status = substr($data, 76, 8).'--';
echo $odometer = substr($data, 84, 9);

mysqli_query($con,"INSERT INTO gps (imei_device,unkn,imei_device_2,ymd,accurate,lat,lon,speed_kph,time_gmt,c_deg,device_status,odometer) 

My concern is this,

(0299444299  BP050000299444299  140819A0538.5869N00013.7049W000.0110944183.3910000000L00004674)
(0299444299  BP050000299444299  140819A0538.5587N00013.8215W017.7111044219.0510000000L0000474C)
(0299444299  BP050000299444299  140819A0538.7077N00014.0409W025.7111145315.8510000000L00004968)
(0299444299  BP050000299444299  140819A0538.8830N00014.1755W000.0111245306.3510000000L00004AAC)

these values will be received on a minute bases, am just wondering how to receive them dinamically and store them in db. I thougth of arrays but am not sure how to go about it...


I have been doing some thinking...
1. I store all data received form gps into a txt file or mysql db
2. Read from the txt file/db
3. Use cronjob/deamon to ran the script (while loop) every minute or two
4. Am not sure what is the best approch when it comes to storing and reading the gps data, TXT FILE OR MYSQL DB?
Am thinking about load on the server and so on...


MySQL would be my choice. You can insert them as they come in. Servers are made for load. Writing to a text-file can cause you to lose all data if something goes wrong. That chance is much smaller with a database.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.