subscribe to our Youtube


14163 questions

16817 answers


54086 members

0 votes
1,181 views 1 comments
# Python AVL data parser

self._codec_id = int.from_bytes(raw_packet[0:1], 'big')

self._number_of_data1 = int.from_bytes(raw_packet[1:2], 'big')

print(self._codec_id) # returns 8

print(self._number_of_data1) # returns 5


# now we know that we have 5 number of data (records) in the received data, so we are gonna loop the range of "number_of_data".

# this is where the problem occurs, the IO element contains x bytes, the AVL data always start with the timestamp (8 bytes) on place 2:10 in the first run,

# how will i be able to find the end_offset of this record, we know that the IO element in the first run comes from raw_packet[26:], but we need to know the end_offset

# for the io element in this record so we can continue to next record of data.


for i in range(self._number_of_data1):

    timestamp = datetime.datetime.fromtimestamp(

        (int.from_bytes(raw_packet[2:10], 'big') / 1000),



    io_element = StreamingAVLDataPacket.parse_io_element(raw_packet[26:])


# hope someone can help me, maybe i'am looking at this the wrong way.

1 Answer

+2 votes


It might easier for you to simply read all received data byte-by-byte instead of trying to segment it in the first place.

For example:

 - At the beginning of received data your code will see "0805" numbers (Indicating Codec ID = 8 and that 5 data records is received)

 - Therefore you can start 5 cycles, but do not specify at which byte they should end. E.g. you can run infinite while cycle (which would be run 5 times in the row, for 5 records)

 - Inside the cycle, read each byte one by one and parse the data. At first that would be UTC timestamp and GPS information, then I/O element part, in which there will be information how many I/O element records are present in total and how many of them are 1/2/4/8 bytes long.

 - This means that when your application would reach end of 8 bytes I/O element records (e.g. read last 8 byte I/O records, or find out, that no 8 byte records are present), it would know that this is the end of first GPS data record (out of initial 5). At this point you can break/escape the cycle, so that cycle could repeat for next GPS data record.

Hope this explanation how everything could be achieved was understandable. You probably already have similar information, but if you do not, here you can find good example how to handle AVL data records:

Teltonika also have made AVL data reader/parser, which you can implement into your server (source codes are available), or use them as a reference point. Applications can be downloaded from here:

Best answer
Thanks, that was very helpful :)