Teltonika Data Sending Protocols
Teltonika Data Sending Protocols
Introduction
A codec is a device or computer program for encoding or decoding a digital data stream or signal. Codec is a portmanteau of coder-decoder. A codec
encodes a data stream or a signal for transmission and storage, possibly in encrypted form, and the decoder function reverses the encoding for
playback or editing.
Also, there are using two data transport protocols: TCP and UDP. But it is not important which one will be used in Codec.
Codec 8
Protocol Overview
Codec8 – a main FM device protocol that is used for sending data to the server.
0x00000000 Data Field Length Codec ID Number of Data 1 AVL Data Number of Data 2 CRC-16
(Preamble)
4 bytes 4 bytes 1 byte 1 byte X bytes 1 byte 4 bytes
Note: for FMB630, FMB640 and FM63XY, minimum AVL record size is 45 bytes (all IO elements disabled). Maximum AVL record size is 255 bytes. Maximum
AVL packet size is 512 bytes. For other devices, the minimum AVL record size is 45 bytes (all IO elements disabled). Maximum AVL packet size is 1280
bytes.
AVL Data
Timestamp – a difference, in milliseconds, between the current time and midnight, January, 1970 UTC (UNIX time).
Priority – field which define AVL data priority (more informationbelow).
GPS Element – location information of the AVL data (more information below).
IO Element – additional configurable information from device (more informationbelow).
Priority
The below table represents Priority values. Packet priority depends on device configuration and records sent.
Priority
0 Low
1 High
2 Panic
GPS element
Longitude and latitude are integer values built from degrees, minutes, seconds and milliseconds by formula:
Where:
d – Degrees; m – Minutes; s – Seconds; ms – Milliseconds; p – Precision(10000000)
If longitude is in west or latitude in south, multiply result by –1.
Note:
To determine if the coordinate is negative, convert it to binary format and check the very first bit. If it is 0, coordinate is positive, if it is 1, coordinate is
negative.
Example:
Received value: 20 9C CA 80 converted to BIN: 00100000 10011100 11001010 10000000 first bit is 0, which means coordinate is positive converted to DEC:
547146368. For more information see two‘s complement arithmetic.
IO Element
Event IO ID 1 byte Event IO ID – if data is acquired on event – this field defines which IO property has changed and
N of Total IO 1 byte generated an event. For example, when if Ignition state changed and it generate event, Event IOID
will be 0xEF (AVL ID: 239). If it’s not eventual record – the value is 0.
N1 of One Byte IO 1 byte
1’st IO ID 1 byte N – a total number of properties coming with record (N = N1 + N2 + N4 + N8).
1’st IO Value 1 byte N1 – number of properties, which length is 1 byte.
N2 – number of properties, which length is 2 bytes.
... N4 – number of properties, which length is 4 bytes.
N1’th IO ID 1 byte N8 – number of properties, which length is 8 bytes.
N’th IO ID - AVL ID.
N1’th IO Value 1 byte
N’th IO Value - AVL ID value.
N2 of Two Bytes 1 byte
1’st IO ID 1 byte
1’st IO Value 2 bytes
...
N2’th IO ID 1 byte
N2’th IO Value 2 bytes
N4 of Four Bytes 1 byte
1’st IO ID 1 byte
1’st IO Value 4 bytes
...
N4’th IO ID 1 byte
N4’th IO Value 4 byte
N8 of Eight Bytes 1 byte
1’st IO ID 1 byte
1’st IO Value 8 byte
...
N8’IO ID 1 byte
N8’IO Value 8 bytes
First, when the module connects to the server, the module sends its IMEI. First comes a short identifying the number of bytes written and then goes IMEI
as text (bytes).
For example, IMEI 356307042441013 would be sent as 000F333536333037303432343431303133 .
First two bytes denote IMEI length. In this case 0x000F means, that IMEI is 15 bytes long.
After receiving IMEI, server should determine if it would accept data from this module. If yes, server will reply to module 01, if not - 00. Note that
confirmation should be sent as binary packet. I.e. 1 byte 0x01 or 0x00.
Then the module starts to send the first AVL data packet. After the server receives a packet and parses it, the server must report to the module number
of data received as integer (four bytes).
If sent data number and reported by the server doesn’t match module resends sent data.
Example:
Four Zero Bytes – 0x00000000, Codec ID – 0x08, CRC of “AVL Data Array”
Examples
Hexadecimal stream of AVL Data Packet receiving and response in these examples are given in hexadecimal form. The different fields of packets are
separated into different table columns for better readability and some of them are converted to ASCII values for better understanding.
1'st example
Receiving one data record with each element property (1 byte, 2 bytes, 4 byte and 8 byte).
Parsed:
2'nd example
Receiving one data record with one or two different element properties (1 byte, 2 byte).
Parsed:
3'rd example
Receiving two or more data records with one or more different element properties.
Parsed:
UDP Datagram
Example 2 bytes
Packet ID 2 bytes
Not Usable Byte 1 byte
Packet Payload Variable
Example – packet length (excluding this field) in big ending byte order.
Packet ID – packet ID unique for this channel.
Not Usable Byte – not usable byte.
Packet payload – data payload.
Acknowledgment packet
Acknowledgment packet should have the same Packet ID as an acknowledged data packet and empty Data Payload. Acknowledgment should be sent in
binary format.
Acknowledgment Packet
Packet Length Packet ID Not Usable Byte
2 bytes 2 bytes 1 byte
The below table represents the Server Response Packet Payload structure.
Example:
Packet ID – 0xCAFE, Not Usable Byte – 0x01 Number of Accepted Data – 0x02
0005CAFE01 DD02
Example
Hexadecimal stream of AVL Data Packet receiving and response in this example are given in hexadecimal form. The different fields of packet are
separate into different table columns for better readability and some of them are converted to ASCII values for better understanding.
Parsed:
Parsed:
Codec 8 Extended
Protocols overview
Codec8 Extended is used for FMBXXX family devices. This protocol looks familiar to Codec8 but they have some differences. Main differences between
are shown in below table:
0x00000000
(Preamble) Data Field Length Codec ID Number of Data 1 AVL Data Number of Data 2 CRC-16
AVL Data
Timestamp – a difference, in milliseconds, between the current time and midnight, January 1970 UTC (UNIX time).
Priority – field which define AVL data priority (more informationbelow).
GPS Element – locational information of the AVL data (more information below).
IO Element – additional configurable information from device (more informationbelow).
Priority
The below table represents Priority values. Packet priority depends on device configuration and records sent.
Priority
0 Low
1 High
2 Panic
GPS element
Longitude and latitude are integer values built from degrees, minutes, seconds and milliseconds by formula:
Where:
d – Degrees; m – Minutes; s – Seconds; ms – Milliseconds; p – Precision(10000000)
If longitude is in west or latitude in south, multiply result by –1.
Note:
To determine if the coordinate is negative, convert it to binary format and check the very first bit. If it is 0, coordinate is positive, if it is 1, coordinate is
negative.
Example:
Received value: 20 9C CA 80 converted to BIN: 00100000 10011100 11001010 10000000 first bit is 0, which means coordinate is positive converted to DEC:
547146368. For more information see two‘s complement arithmetic.
IO Element
Event IO ID 2 bytes Event IO ID – if data is acquired on event – this field defines which IO property has changed and
N of Total IO 2 bytes generated an event. For example, when if Ignition state changed and it generate event, Event IOID
N1 of One Byte IO will be 0xEF (AVL ID: 239). If it’s not eventual record – the value is 0.
2 bytes
1’st IO ID 2 bytes
1’st IO Value 1 byte
... N – a total number of properties coming with record (N = N1 + N2 + N4 + N8).
N1 – number of properties, which length is 1 byte.
N1’th IO ID 2 bytes
N2 – number of properties, which length is 2 bytes.
N1’th IO Value 1 byte N4 – number of properties, which length is 4 bytes.
N2 of Two Bytes 2 bytes N8 – number of properties, which length is 8 bytes.
NX – a number of properties, which length is defined by length element. N’th IO ID - AVL ID.
1’st IO ID 2 bytes N'th Lenght - AVL ID value lenght.
1’st IO Value 2 bytes N’th IO Value - AVL ID value.
...
N2’th IO ID 2 bytes
N2’th IO Value 2 bytes
N4 of Four Bytes 2 bytes
1’st IO ID 2 bytes
1’st IO Value 4 bytes
...
N4’th IO ID 2 bytes
N4’th IO Value 4 byte
N8 of Eight Bytes 2 bytes
1’st IO ID 2 bytes
1’st IO Value 8 byte
...
N8’IO ID 2 bytes
N8’IO Value 8 bytes
NX of X Byte IO 2 bytes
1’st IO ID 2 bytes
1’st IO Length 2 bytes
1’st IO Value Defined by lenght
...
2 bytes
2 bytes
Defined by lenght
Communication with the server is the same as with the Codec8 protocol, except in Codec8 Extended protocol Codec ID is 0x8E.
Example:
Example
Hexadecimal stream of AVL Data Packet receiving and response in this example are given in hexadecimal form. The different fields of packet are
separate into different table columns for better readability and some of them are converted to ASCII values for better understanding.
Received data in hexadecimal stream:
000000000000004A8E010000016B412CEE000100000000000000000000000000000000010005000100010100010011001D00010010015E2C880002000B000000003544C87
A000E000000001DD7E06A00000100002994
Parsed data:
AVL data packet is the same as with Codec8, except Codec ID is changed to 0x8E. AVL Data encoding was performed according to Codec8 Extended
protocol.
The module sends the UDP channel packet with an encapsulated AVL data packet. The server sends the UDP channel packet with an encapsulated
response module that validates AVL Packet ID and the Number of accepted AVL elements. If server response with valid AVL Packet ID is not received
within configured timeout, the module can retry sending.
Example:
Packet ID – 0xCAFE, Not Usable Byte – 0x01 Number of Accepted Data – 0x02
0005CAFE01 DD02
Example
Hexadecimal stream of AVL Data Packet receiving and response in this example are given in hexadecimal form. The different fields of packet are
separate into different table columns for better readability and some of them are converted to ASCII values for better understanding.
Parsed:
Parsed:
Codec 16
Protocol overview
Codec16 is using for FMB630/FM63XY devices. This protocol looks familiar like Codec8 but they have some differences. Main differences between are
shown in table below:
Codec8 Codec16
Codec ID 0x08 0x10
AVL Data IO element ID event length 1 byte 2 bytes
AVL Data IO element AVL IDlength 1 byte 2 bytes
Generation Type Not Using Is Using
Note: Codec16 is supported from firmware – 00.03.xx and newer. (FMB630/FM63XY) || AVL ID‘s which are higher than 255 will can be used only in
Codec16 protocol.
0x00000000
Data Field Length Codec ID Number of Data 1 AVL Data Number of Data 2 CRC-16
Note: for FMB630 and FM63XY, minimum AVL record size is 45 bytes (all IO elements disabled). Maximum AVL record sizeis 255 bytes.
AVL Data
Timestamp – a difference, in milliseconds, between the current time and midnight, January 1970 UTC (UNIX time).
Priority – field which define AVL data priority (more informationbelow).
GPS Element – location information of the AVL data (more information below).
IO Element – additional configurable information from device (more informationbelow).
Priority
The below table represents Priority values. Packet priority depends on device configuration and records sent.
Priority
0 Low
1 High
2 Panic
GPS element
Longitude and latitude are integer values built from degrees, minutes, seconds and milliseconds by formula:
Where:
d – Degrees; m – Minutes; s – Seconds; ms – Milliseconds; p – Precision(10000000)
If longitude is in west or latitude in south, multiply result by –1.
Note:
To determine if the coordinate is negative, convert it to binary format and check the very first bit. If it is 0, coordinate is positive, if it is 1, coordinate is
negative.
Example:
Received value: 20 9C CA 80 converted to BIN: 00100000 10011100 11001010 10000000 first bit is 0, which means coordinate is positive converted to DEC:
547146368. For more information see two‘s complement arithmetic.
IO Element
Event IO ID 2 bytes Event IO ID – if data is acquired on event – this field defines which IO property has changed and
Generation Type 1 byte generated an event. For example, when if Ignition state changed and it generate event, Event IOID
N of Total IO will be 0xEF (AVL ID: 239). If it’s not eventual record – the value is 0.
1 byte
N1 of One Byte IO 1 byte
1’st IO ID 2 bytes
1’st IO Value 1 byte Generation type - data event generation type. More information about it you can find here.
N – a total number of properties coming with record (N = N1 + N2 + N4 + N8).
...
N1 – number of properties, which length is 1 byte.
N1’th IO ID 2 bytes N2 – number of properties, which length is 2 bytes.
N1’th IO Value 1 byte N4 – number of properties, which length is 4 bytes.
N8 – number of properties, which length is 8 bytes.
N2 of Two Bytes 1 byte
N’th IO ID - AVL ID.
1’st IO ID 2 bytes N’th IO Value - AVL ID value.
1’st IO Value 2 bytes
...
N2’th IO ID 2 bytes
N2’th IO Value 2 bytes
N4 of Four Bytes 1 byte
1’st IO ID 2 bytes
1’st IO Value 4 bytes
...
N4’th IO ID 2 bytes
N4’th IO Value 4 byte
N8 of Eight Bytes 1 byte
1’st IO ID 2 bytes
1’st IO Value 8 byte
...
N8’IO ID 2 bytes
N8’IO Value 8 bytes
Generation type
Communication with server is the same as with Codec8 protocol, except in Codec16 protocol Codec ID is 0x10 and has generation type.
Example:
Example
Hexadecimal stream of AVL Data Packet receiving and response in this example are given in hexadecimal form. The different fields of packet are
separate into different table columns for better readability and some of them are converted to ASCII values for better understanding.
Parsed data:
AVL data packet is the same as with Codec8, except Codec ID is changed to 0x10. AVL Data encoding performed according to Codec16protocol.
The module sends the UDP channel packet with an encapsulated AVL data packet. The server sends the UDP channel packet with an encapsulated
response module validates AVL Packet ID and the Number of accepted AVL elements. If server response with valid AVL Packet ID is not received within
configured timeout, the module can retry sending.
Example:
Module sends the data:
Packet ID – 0xCAFE, Not Usable Byte – 0x01 Number of Accepted Data – 0x02
0005CAFE01 DD02
Example
Hexadecimal stream of AVL Data Packet receiving and response in this example are given in hexadecimal form. The different fields of packet are
separate into different table columns for better readability and some of them are converted to ASCII values for better understanding.
Parsed:
Parsed:
Codec 12
About Codec12
Codec12 is the original and main Teltonika protocol for device-server communication over GPRS messages. Codec12 GPRS commands can be used for
sending configuration, debug, digital outputs control commands, or other (special purpose command on special firmware versions). This protocol is
also necessary for using FMB630/FM6300/FM5300/FM5500/FM4200 features like: Garmin, LCD communication, COM TCP Link Mode.
First, the Teltonika device opens the GPRS session and sends AVL data to the server (refer device protocols). Once all records are sent and correct sent
data array acknowledgment is received by device then GPRS commands in Hex can be sent to the device.
The ACK (acknowledge of IMEI from server) is a one-byte constant 0x01. The acknowledgment of each data array send from the device is four bytes
integer – a number of received records.
Note, that the GPRS session should remain active between device and server, while GPRS commands are sent. For this reason, active datalink timeout
(global parameters in device configuration) is recommended to be set to 259200 (maximum value).
0x00000000 Response
Data Size Codec ID Type (0x06) Response Size Response Response Quantity 2 CRC-16
(Preamble) Quantity 1
4 bytes 4 bytes 1 byte 1 byte 1 byte 4 bytes X bytes 1 byte 4 bytes
Note that difference between commands and responses is message type field: 0x05 means command and 0x06 means response.
Parsed:
Server Command
Server Command Part HEX Code Part
Zero Bytes 00 00 00 00
Data Size 00 00 00 0F
Codec ID 0C
Command Quantity 1 01
Command Type 05
Command Size 00 00 00 07
Command 67 65 74 69 6E 66 6F
Command Quantity 2 01
CRC-16 00 00 43 12
Note that Server Command converted from HEX to ASCII means getinfo
Parsed:
Device Answer
Device Answer Part HEX Code Part
Zero Bytes 00 00 00 00
Data Size 00 00 00 90
Codec ID 0C
Response Quantity 1 01
Response Type 06
Response Size 00 00 00 88
49 4E 49 3A 32 30 31 39 2F 37 2F 32 32 20 37 3A 32 32 20 52 54 43 3A 32 30 31
39 2F 37 2F 32 32 20 37 3A 35 33 20 52 53 54 3A 32 20 45 52 52 3A 31 20 53 52
3A 30 20 42 52 3A 30 20 43 46 3A 30 20 46 47 3A 30 20 46 4C 3A 30 20 54 55
Response 3A 30 2F 30 20 55 54 3A 30 20 53 4D 53 3A 30 20 4E 4F 47 50 53 3A 30 3A 33
30 20 47 50 53 3A 31 20 53 41 54 3A 30 20 52 53 3A 33 20 52 46 3A 36 35 20
53 46 3A 31 20 4D 44 3A 30
Response Quantity 2 01
CRC-16 00 00 C7 8F
Parsed:
Server Command
Server Command Part HEX Code Part
Zero Bytes 00 00 00 00
Data Size 00 00 00 0D
Codec ID 0C
Command Quantity 1 01
Command Type 05
Command Size 00 00 00 05
Command 67 65 74 69 6F
Command Quantity 2 01
CRC-16 00 00 00 CB
Note that Server Command converted from HEX to ASCII means getio
Parsed:
Device Answer
Device Answer Part HEX Code Part
Zero Bytes 00 00 00 00
Data Size 00 00 00 37
Codec ID 0C
Response Quantity 1 01
Response Type 06
Response Size 00 00 00 2F
Response 44 49 31 3A 31 20 44 49 32 3A 30 20 44 49 33 3A 30 20 41 49 4E 31 3A 30 20
41 49 4E 32 3A 31 36 39 32 34 20 44 4F 31 3A 30 20 44 4F 32 3A 31
Response Quantity 2 01
CRC-16 00 00 66 E3
Codec 13
About Codec13
Codec13 is the original Teltonika protocol for device-server communication over GPRS messages and it is based on Codec12 protocol. The main
differences of Codec13 are that timestamp is using in messages and communication is one way only (Codec13 is used for Device -> Server sending).
Preamble – the packet starts with preamble field (four zero bytes).
Data Size – size is calculated from the Codec ID field to the second Command Quantity field.
Codec ID – in Codec13 it is always 0x0D.
Command Quantity 1 – 0x01, it is ignored when parsing the message.
Command Type – it is always 0x06 since the packet is direction is FM->Server.
Command Size – command size field includes size of timestamp too, so it is equal to the size of payload + size of timestamp.
Timestamp – a difference, in milliseconds, between the current time and midnight, January, 1970 UTC (UNIX time).
Command – actual received data.
Command Quantity 2 – a byte which defines how many records (commands) are in the packet. This byte will not be parsed but it’s recommended that it
should contain the same value as Command/Response Quantity 1.
CRC-16 – calculated from Codec ID to the Second Number of Data. CRC (Cyclic Redundancy Check) is an error-detecting code using for detect accidental
changes to RAW data. For calculation we are using CRC-16/IBM.
Note: Codec13 packets are used only when “Message Timestamp” parameter in RS232 settings isenabled.
Command parsing example
Hexadecimal stream of GPRS command in this example is given in hexadecimal form. The different fields of message are separate into different table
columns for better readability and some of them are converted to ASCII values for better understanding.
Hexadecimal stream:
00000000000000170D01050000000F0000016C0A81C320676574696E666F0100006855
Parsed:
Server Command
Server Command Part HEX Code Part
Zero Bytes 00 00 00 00
Data Size 00 00 00 17
Codec ID 0D
Command Quantity 1 01
Command Type 06
Command Size 00 00 00 0F
Timestamp 00 00 01 6C 0A 81 C3 20
Command 67 65 74 69 6E 66 6F
Command Quantity 2 01
CRC-16 00 00 68 55
Note that Server Command converted from HEX to ASCII means getinfo
Codec 14
About Codec14
Codec14 is the original Teltonika protocol for device-server communication over GPRS messages and it is based on Codec12 protocol.
The main difference of Codec14 is that device will answer to GPRS command if the device physical IMEI number matches specified IMEI number in GPRS
command.
Codec14 GPRS commands can be used for sending configuration, debug, digital outputs control commands, or other (special purpose command on
special firmware versions).
0x05 Command
0x00000000 0x0E (Codec Command Command
Data size (Message size + IMEIsize IMEI (HEX) Command CRC-16
(preamble) ID) quantity quantity
type) (8 bytes)
4 bytes 4 bytes 1 bytes 1 bytes 1 bytes 4 bytes 8 bytes X bytes 1 bytes 4 bytes
Parsed:
Note that Server Command converted from HEX to ASCII means getver
Parsed:
Device Answer
Device Answer Part HEX Code Part
Zero Bytes 00 00 00 00
Data Size 00 00 00 37
Codec ID 0E
Response Quantity 1 01
Response Type 06
Response Size 00 00 00 A3
IMEI 03 52 09 30 81 45 22 51
Response 56 65 72 3A 30 33 2E 31 38 2E 31 34 5F 30 34 20 47 50 53 3A 41 58 4E 5F 35 2E
31 30 5F 33 33 33 33 20 48 77 3A 46 4D 42 31 32 30 20 4D 6F 64 3A 31 35 20
49 4D 45 49 3A 33 35 32 30 39 33 30 38 31 34 35 32 32 35 31 20 49 6E 69 74
3A 32 30 31 38 2D 31 31 2D 32 32 20 37 3A 31 33 20 55 70 74 69 6D 65 3A 31
37 32 33 34 20 4D 41 43 3A 36 30 42 44 44 30 30 31 36 32 36 31 20 53 50 43
3A 31 28 30 29 20 41 58 4C 3A 30 20 4F 42 44 3A 30 20 42 4C 3A 31 2E 36 20
42 54 3A 34
Response Quantity 2 01
CRC-16 00 00 7A AE
Parsed:
Device Answer
Device Answer Part HEX Code Part
Zero Bytes 00 00 00 00
Data Size 00 00 00 10
Codec ID 0E
Response Quantity 1 01
Response Type 11
Response Size 00 00 00 08
IMEI 03 52 09 30 81 45 24 68
Response Quantity 2 01
CRC-16 00 00 32 AC
Differences between Codec 12, Codec 13 and Codec 14
In the table below you will see differences between Codec12, Codec13 and Codec14.
Encoding
To be able to compress 24 GPS data entries into one SMS (140 octets), the data is encoded extensively using bit fields. Data packet can be interpreted as
a bitstream, where all bits are numbered as follows:
Bits in a byte are numbered starting from the least significant bit. A field of 25 bits would consist of bits 0 to 24 where 0 is the least significant bit and bit
24 – most significant bit.
Structure
Below in the tables you will see SMS Data Structure:
The time of only the first GPS data element is specified in Timestamp field. Time corresponding to each further element can be computed as
elementTime = Timestamp + (1 hour * elementNumber).
SMS Events
When Configured to generate SMS event user will get this SMS upon event:
<Year/Month/Day> <Hour:Minute:Second> P:<profile_nr> <SMS Text> Val:<Event Value> Lon:<longitude> Lat:<latitude> Q:<HDOP>
Example:
2016./04/11 12:00:00 P:3 Digital Input 1 Val:1 Lon:51.12258 Lat: 25.7461 Q:0.6
CRC-16
CRC (Cyclic Redundancy Check) is an error-detecting code using to detect accidental changes to RAW data. The algorithm on how to calculate CRC-16
(also known as CRC-16/IBM) you will find below.