











{"author":"Faiq Najib Al-Aziz","body":"\nWhen I was first trusted with the backend for hundreds of GPS trackers, I figured the job was just a standard REST API: the device sends a `POST /api/location` with JSON, the server saves it to the database, done. Easy, right? Hahaha.\n\nI was wrong. The backend was eventually migrated from Laravel to Go, covering 370+ endpoints. I tell the full story in my [Hijrah Backend narrative series](/en/writing/2026/hijrah-backend-01/). The series you're reading is its tutorial counterpart: rebuilding the backend from scratch, with code you can follow along.\n\nGPS trackers don't speak HTTP. No JSON either. A TCP connection carries raw bytes such as `\\x00\\x00\\x00\\x2f\\x8e\\x01\\x04\\x01\\x03...`, with no headers, content-type, or any hint at all. Each brand also has its own way of arranging those bytes.\n\nIn this article I'll first talk about how GPS trackers chat with a server. It's not the decoder tutorial yet, that's in [Part 3](/en/writing/2026/decode-packet-gt06-teltonika/). We start with the concepts you need before writing any parser code.\n\n## What Is a GPS Tracker, Really?\n\nA GPS tracker is an embedded device built around two core modules:\n\n1. **GPS module**: receives satellite signals to work out position (latitude, longitude, altitude, speed, heading).\n2. **GSM/LTE module**: sends that position data to your server over the cellular network.\n\nBesides those, trackers usually have:\n\n- **Digital I/O**: sensors for door open/closed, ignition (engine on), and SOS buttons\n- **Analog inputs**: fuel level and temperature sensors\n- **Accelerometer**: shock detection (crashes or harsh braking)\n- **Internal battery**: backup when main power is disconnected\n\nData from all these sensors is bundled into one packet and pushed to the server periodically, usually every 10 to 30 seconds while moving, and less often when parked to save data.\n\n## Why TCP Instead of HTTP?\n\nMy first question was the same: why don't the devices just use an HTTP REST API?\n\nThere are four reasons.\n\n### 1. Bandwidth Efficiency\n\nHTTP requests carry a lot of overhead. Headers alone can easily eat 500+ bytes (`Host`, `Content-Type`, `Accept`, `Authorization`, and so on), while a typical binary GPS packet is only 40 to 60 bytes. Over flaky 2G/3G links, with SIM data billed per megabyte, every byte counts.\n\n### 2. Persistent Connections\n\nA tracker needs to keep its connection alive so the server can send commands anytime: \"cut the engine\" (engine kill), \"update reporting interval\", or \"send location now\". HTTP is request-response. Sending a command while the device isn't making a request needs another mechanism, like polling or a separate channel.\n\n### 3. Full Control Over the Data Layout\n\nHTTP forces a certain structure (methods, headers, body, status codes). A custom binary protocol lets manufacturers design the format as compactly as they like. With bitmasks, one byte can stand for three or four fields.\n\n### 4. Hardware Constraints\n\nMany GPS trackers use microcontrollers with limited resources (often 64KB RAM and a 48MHz clock). An HTTP stack (header parsing, TLS handshakes, JSON serialization) eats too much of that. Raw TCP sockets are much lighter.\n\n## How GPS Tracker Communication Works\n\nThe flow looks like this:\n\n```\nDevice                          Server\n  │                               │\n  │──── Connect (TCP) ───────────→│\n  │                               │\n  │──── Login packet (IMEI) ─────→│\n  │                               │\n  │←─── ACK / Login response ─────│\n  │                               │\n  │──── Location data ───────────→│  (loop, every N seconds)\n  │←─── ACK ──────────────────────│\n  │                               │\n  │←─── Command (optional) ───────│  (server → device)\n  │──── Command response ────────→│\n  │                               │\n  │──── Heartbeat (keep-alive) ──→│  (when idle)\n  │←─── Heartbeat ACK ────────────│\n  │                               │\n```\n\n### Phase 1: Connection \u0026 Login\n\nThe tracker opens a TCP socket to the server's IP and port. Once connected, it sends a **login packet**, usually containing its IMEI (International Mobile Equipment Identity), a unique 15-digit number that identifies the device.\n\nThe server replies with an ACK. If the IMEI is unknown or unauthorized, the server can close the connection or ignore the data.\n\n### Phase 2: Data Reporting\n\nAfter a successful login, the tracker starts sending location data at regular intervals. Many protocols also report on events:\n\n- When motion is detected\n- When a distance threshold from the previous point is crossed (distance-based reporting)\n- When ignition is switched on or off\n- When the SOS button is pressed\n- When a geofence is breached\n\nEvery location packet contains at least a timestamp, latitude, and longitude. There's usually speed, heading/azimuth, altitude, I/O status (ignition, door, alarms), and battery level too.\n\n### Phase 3: Server Commands\n\nThe server can send commands to any online tracker. For example:\n\n- **Reboot device**: handy when firmware hangs\n- **Set reporting interval**: change how often it sends data\n- **Engine cut**: disable the starter relay (anti-theft)\n- **Listen-in**: open the onboard mic for audio monitoring\n- **Request current location**: ask for a position right now\n\n### Phase 4: Heartbeat / Keep-Alive\n\nWhen the vehicle is parked and idle, the tracker keeps the TCP connection alive by sending a heartbeat packet every 2 to 5 minutes. This prevents NAT timeouts and keeps the socket reachable.\n\n## Anatomy of a GPS Packet\n\nFormats differ across brands, but most binary GPS packets follow this general layout:\n\n```\n┌──────────┬──────────┬────────────┬─────────────┬──────────┬──────────┐\n│  Start   │  Length  │  Protocol  │   Payload   │   CRC    │   End    │\n│  Marker  │  Bytes   │    ID      │   (Data)    │  Check   │  Marker  │\n└──────────┴──────────┴────────────┴─────────────┴──────────┴──────────┘\n```\n\n- **Start marker**: fixed bytes marking the start of a packet (e.g., `\\x78\\x78` for GT06, or four zero bytes `\\x00\\x00\\x00\\x00` for Teltonika)\n- **Length**: payload byte length (so the server knows when a full packet has been read)\n- **Protocol ID / Codec ID**: identifier for the data type (location, alarm, heartbeat, command response)\n- **Payload**: the actual data (IMEI, coordinates, I/O status, etc.)\n- **CRC**: checksum to validate data integrity\n- **End marker**: fixed bytes marking the end of a packet (e.g., `\\x0d\\x0a` for GT06)\n\n### Example: GT06 (Concox) Packet Structure\n\nGT06 is common in Indonesia because the hardware is cheap and easy to find. Its structure looks like this:\n\n```\n78 78      Start bit (2 bytes)\n0D         Length (1 byte: spanning protocol number through CRC, inclusive)\n01         Protocol number (login = 0x01)\n01 23 45 67 89 01 23 45    IMEI (8 bytes, BCD encoded)\n00 01      Serial number (2 bytes)\n8C DD      CRC-ITU (2 bytes)\n0D 0A      Stop bit (2 bytes)\n```\n\nThe example above is a login packet from the Concox GT06 v1.8.1 datasheet for terminal ID `123456789012345` (a 15-digit IMEI: 8 BCD bytes hold 16 nibbles, with the leading nibble dropped). CRC-ITU is computed from the _length_ byte through the _serial number_ (inclusive); we'll go through CRC variants in [Part 3](/en/writing/2026/decode-packet-gt06-teltonika/). The `0x7878` header and `0x0D0A` trailer are kind of the GT06 \"signature\". When you spot those bytes in raw TCP logs, you know right away it's Concox/GT06 family hardware.\n\n### Example: Teltonika Packet Structure\n\nTeltonika (FMB and FMTC series) takes a slightly different approach. The structure is more orderly and built around \"codec\" frames:\n\n```\n0000 0000        Preamble (4 zero bytes)\n0000 0039         Data field length (4 bytes)\n08               Codec ID (1 byte: 0x08 = codec8, 0x0E = codec8 extended)\n01               Number of data (1 byte: count of AVL records)\n...              AVL data (records only; IMEI is sent separately during the handshake)\n...              Number of data (repeat verification)\n0000 0XXX         CRC-16 (4 bytes)\n```\n\nTeltonika uses a 4-byte length prefix and CRC-16, while GT06 uses a 1-byte length, 2-byte CRC-ITU, and a serial number to match ACKs. These differences will matter when we write decoders in Part 3.\n\n## Popular Protocols in the Field\n\nFrom my experience with GPS tracking in production, these are the protocols and brands you're likely to run into:\n\n| Protocol       | Common Brands                        | Format         | Description                                 |\n| -------------- | ------------------------------------ | -------------- | ------------------------------------------- |\n| **GT06**       | Concox, Coban, Xexun, diverse OEMs   | Binary         | Most affordable, widest variety of clones   |\n| **Teltonika**  | Teltonika FMB/FMTC/FM                | Binary         | Premium tier, solid docs, codec system      |\n| **Meitrack**   | Meitrack MVT/MST                     | Binary         | Common across enterprise fleet deployments  |\n| **Wialon IPS** | Various brands (Universal)           | Text (ASCII)   | Comma-separated, human-readable format      |\n| **H02**        | H02/GPS103                           | Text (ASCII)   | Simple, common in budget trackers           |\n| **MQTT**       | Modern multi-sensor hardware         | JSON over MQTT | Emerging trend: 4G hardware pushing JSON    |\n\n### Binary vs. Text Protocols\n\nGPS protocols fall into two big camps.\n\n**Binary protocols** (Teltonika, GT06, Meitrack):\n\n- Every byte has a precise meaning, often packing several fields\n- Very bandwidth-efficient (1 byte = 8 bits = 8 independent boolean flags)\n- Harder for humans to read (`\\x8e\\x01\\x04` vs. `lat=-6.2,lng=106.8`)\n- Needs thorough vendor documentation to parse correctly\n\n**Text protocols** (Wialon, H02):\n\n- Directly readable ASCII strings: `#L#359769030123456;NA`\n- Easy to debug in plaintext logs\n- Higher bandwidth footprint\n- Good for quick prototyping or low-resource devices\n\n### The Trend: MQTT and JSON\n\nLately I've started running into newer trackers (4G/LTE, Cat-M1, NB-IoT) that use MQTT with JSON payloads. A payload can look like this:\n\n```json\n{\n  \"imei\": \"359769030123456\",\n  \"lat\": -6.2,\n  \"lng\": 106.816666,\n  \"speed\": 42,\n  \"course\": 180,\n  \"ignition\": true,\n  \"timestamp\": \"2026-09-08T10:30:00Z\"\n}\n```\n\nJSON is easier to parse, human-readable, and doesn't need a special low-level protocol spec. But in Indonesia 2G/3G devices are still common and still use binary TCP. Both approaches will probably live side by side for the next few years.\n\n## Misconceptions I Learned the Hard Way\n\n### \"Reading one vendor's documentation is enough\"\n\nWrong. GT06 has dozens of protocol variations because countless white-label OEM clones tweaked small framing details. Concox GT06, Coban GPS103, and \"generic GT06\" have subtle differences that will crash your parser if you don't handle those edge cases.\n\n### \"IMEIs are always unique per device\"\n\nIn theory, yes. In practice, cheap clone hardware can ship with duplicate or invalid IMEIs. Give your database its own surrogate `device_id` primary key, and don't use raw IMEIs as primary keys without normalization.\n\n### \"An active TCP connection means the tracker is online\"\n\nNot always. NAT table drops, silent carrier-level resets, and frozen devices can leave a socket looking alive on the server while the device has been dead for hours. That's why heartbeat/keep-alive timeouts are a must.\n\n### \"Every tracker reports timestamps in UTC\"\n\nMost do, but some brands send timestamps in local time (such as UTC+7 for Indonesia). Check the protocol spec, or better, don't assume and test with a real device.\n\n## Tools for Packet Inspection\n\nBefore writing a decoder, I \"peek\" at the incoming traffic first with a few tools.\n\n### 1. TCP Packet Logger\n\nTo see packet structure, use a simple TCP connection handler that logs incoming bytes. This example only receives and prints data; it does not forward anything to another server:\n\n```go\n// Minimal TCP logger: dump all inbound bytes\nfunc handleConn(conn net.Conn) {\n    defer conn.Close()\n    buf := make([]byte, 1024)\n    for {\n        n, err := conn.Read(buf)\n        if err != nil {\n            break\n        }\n        fmt.Printf(\"%x\\n\", buf[:n]) // print as hex\n    }\n}\n```\n\nHex dumps make it easier to compare packet layouts with vendor datasheets.\n\n### 2. Wireshark\n\nIf you can capture traffic on the server interface, filter Wireshark by `tcp.port == 5094` (or your listening port) to inspect each packet. \"Follow TCP Stream\" shows the full conversation between tracker and server.\n\n### 3. Device Simulators\n\nSome vendors provide simulators. If yours doesn't, record packets from a physical tracker and replay them in tests. That way you don't need a physical device every time you work on a decoder for another protocol.\n\n## What to Have in Your Head Before Moving On\n\nBefore moving on, make sure you've got these:\n\n- **Why GPS devices use TCP sockets rather than HTTP**: bandwidth efficiency, persistent connections, and control over the format\n- **Device-to-server lifecycle**: connect → login → data reporting → commands → heartbeat\n- **Binary packet anatomy**: start marker, length, payload, CRC, end marker\n- **Protocol differences per brand**: binary vs. text, GT06 vs. Teltonika vs. MQTT\n- **Common gotchas**: duplicated IMEIs, TCP \"alive\" but device dead, inconsistent timezones\n\n## What's Next\n\nThis article is part of the **Building a GPS Backend from Scratch** series.\n\nNext up: [Part 2: Building a High-Performance GPS TCP Listener in Go](/en/writing/2026/tcp-listener-gps-go/), where we build a TCP server that handles hundreds of tracker connections concurrently with goroutines.\n\nIf you want to jump straight to reading packets, [Part 3](/en/writing/2026/decode-packet-gt06-teltonika/) covers the details of parsing GT06 and Teltonika binary frames.\n\nFor questions or discussion, head to [Contact](/en/contact/) or subscribe to [RSS](/en/writing/index.xml).\n","body_clean":"When I was first trusted with the backend for hundreds of GPS trackers, I figured the job was just a standard REST API: the device sends a POST /api/location with JSON, the server saves it to the database, done. Easy, right? Hahaha.\nI was wrong. The backend was eventually migrated from Laravel to Go, covering 370+ endpoints. I tell the full story in my Hijrah Backend narrative series. The series you\u0026rsquo;re reading is its tutorial counterpart: rebuilding the backend from scratch, with code you can follow along.\nGPS trackers don\u0026rsquo;t speak HTTP. No JSON either. A TCP connection carries raw bytes such as \\x00\\x00\\x00\\x2f\\x8e\\x01\\x04\\x01\\x03..., with no headers, content-type, or any hint at all. Each brand also has its own way of arranging those bytes.\nIn this article I\u0026rsquo;ll first talk about how GPS trackers chat with a server. It\u0026rsquo;s not the decoder tutorial yet, that\u0026rsquo;s in Part 3. We start with the concepts you need before writing any parser code.\nWhat Is a GPS Tracker, Really? #A GPS tracker is an embedded device built around two core modules:\nGPS module: receives satellite signals to work out position (latitude, longitude, altitude, speed, heading). GSM/LTE module: sends that position data to your server over the cellular network. Besides those, trackers usually have:\nDigital I/O: sensors for door open/closed, ignition (engine on), and SOS buttons Analog inputs: fuel level and temperature sensors Accelerometer: shock detection (crashes or harsh braking) Internal battery: backup when main power is disconnected Data from all these sensors is bundled into one packet and pushed to the server periodically, usually every 10 to 30 seconds while moving, and less often when parked to save data.\nWhy TCP Instead of HTTP? #My first question was the same: why don\u0026rsquo;t the devices just use an HTTP REST API?\nThere are four reasons.\n1. Bandwidth Efficiency #HTTP requests carry a lot of overhead. Headers alone can easily eat 500+ bytes (Host, Content-Type, Accept, Authorization, and so on), while a typical binary GPS packet is only 40 to 60 bytes. Over flaky 2G/3G links, with SIM data billed per megabyte, every byte counts.\n2. Persistent Connections #A tracker needs to keep its connection alive so the server can send commands anytime: \u0026ldquo;cut the engine\u0026rdquo; (engine kill), \u0026ldquo;update reporting interval\u0026rdquo;, or \u0026ldquo;send location now\u0026rdquo;. HTTP is request-response. Sending a command while the device isn\u0026rsquo;t making a request needs another mechanism, like polling or a separate channel.\n3. Full Control Over the Data Layout #HTTP forces a certain structure (methods, headers, body, status codes). A custom binary protocol lets manufacturers design the format as compactly as they like. With bitmasks, one byte can stand for three or four fields.\n4. Hardware Constraints #Many GPS trackers use microcontrollers with limited resources (often 64KB RAM and a 48MHz clock). An HTTP stack (header parsing, TLS handshakes, JSON serialization) eats too much of that. Raw TCP sockets are much lighter.\nHow GPS Tracker Communication Works #The flow looks like this:\nDevice Server │ │ │──── Connect (TCP) ───────────→│ │ │ │──── Login packet (IMEI) ─────→│ │ │ │←─── ACK / Login response ─────│ │ │ │──── Location data ───────────→│ (loop, every N seconds) │←─── ACK ──────────────────────│ │ │ │←─── Command (optional) ───────│ (server → device) │──── Command response ────────→│ │ │ │──── Heartbeat (keep-alive) ──→│ (when idle) │←─── Heartbeat ACK ────────────│ │ │ Phase 1: Connection \u0026amp; Login #The tracker opens a TCP socket to the server\u0026rsquo;s IP and port. Once connected, it sends a login packet, usually containing its IMEI (International Mobile Equipment Identity), a unique 15-digit number that identifies the device.\nThe server replies with an ACK. If the IMEI is unknown or unauthorized, the server can close the connection or ignore the data.\nPhase 2: Data Reporting #After a successful login, the tracker starts sending location data at regular intervals. Many protocols also report on events:\nWhen motion is detected When a distance threshold from the previous point is crossed (distance-based reporting) When ignition is switched on or off When the SOS button is pressed When a geofence is breached Every location packet contains at least a timestamp, latitude, and longitude. There\u0026rsquo;s usually speed, heading/azimuth, altitude, I/O status (ignition, door, alarms), and battery level too.\nPhase 3: Server Commands #The server can send commands to any online tracker. For example:\nReboot device: handy when firmware hangs Set reporting interval: change how often it sends data Engine cut: disable the starter relay (anti-theft) Listen-in: open the onboard mic for audio monitoring Request current location: ask for a position right now Phase 4: Heartbeat / Keep-Alive #When the vehicle is parked and idle, the tracker keeps the TCP connection alive by sending a heartbeat packet every 2 to 5 minutes. This prevents NAT timeouts and keeps the socket reachable.\nAnatomy of a GPS Packet #Formats differ across brands, but most binary GPS packets follow this general layout:\n┌──────────┬──────────┬────────────┬─────────────┬──────────┬──────────┐ │ Start │ Length │ Protocol │ Payload │ CRC │ End │ │ Marker │ Bytes │ ID │ (Data) │ Check │ Marker │ └──────────┴──────────┴────────────┴─────────────┴──────────┴──────────┘ Start marker: fixed bytes marking the start of a packet (e.g., \\x78\\x78 for GT06, or four zero bytes \\x00\\x00\\x00\\x00 for Teltonika) Length: payload byte length (so the server knows when a full packet has been read) Protocol ID / Codec ID: identifier for the data type (location, alarm, heartbeat, command response) Payload: the actual data (IMEI, coordinates, I/O status, etc.) CRC: checksum to validate data integrity End marker: fixed bytes marking the end of a packet (e.g., \\x0d\\x0a for GT06) Example: GT06 (Concox) Packet Structure #GT06 is common in Indonesia because the hardware is cheap and easy to find. Its structure looks like this:\n78 78 Start bit (2 bytes) 0D Length (1 byte: spanning protocol number through CRC, inclusive) 01 Protocol number (login = 0x01) 01 23 45 67 89 01 23 45 IMEI (8 bytes, BCD encoded) 00 01 Serial number (2 bytes) 8C DD CRC-ITU (2 bytes) 0D 0A Stop bit (2 bytes) The example above is a login packet from the Concox GT06 v1.8.1 datasheet for terminal ID 123456789012345 (a 15-digit IMEI: 8 BCD bytes hold 16 nibbles, with the leading nibble dropped). CRC-ITU is computed from the length byte through the serial number (inclusive); we\u0026rsquo;ll go through CRC variants in Part 3. The 0x7878 header and 0x0D0A trailer are kind of the GT06 \u0026ldquo;signature\u0026rdquo;. When you spot those bytes in raw TCP logs, you know right away it\u0026rsquo;s Concox/GT06 family hardware.\nExample: Teltonika Packet Structure #Teltonika (FMB and FMTC series) takes a slightly different approach. The structure is more orderly and built around \u0026ldquo;codec\u0026rdquo; frames:\n0000 0000 Preamble (4 zero bytes) 0000 0039 Data field length (4 bytes) 08 Codec ID (1 byte: 0x08 = codec8, 0x0E = codec8 extended) 01 Number of data (1 byte: count of AVL records) ... AVL data (records only; IMEI is sent separately during the handshake) ... Number of data (repeat verification) 0000 0XXX CRC-16 (4 bytes) Teltonika uses a 4-byte length prefix and CRC-16, while GT06 uses a 1-byte length, 2-byte CRC-ITU, and a serial number to match ACKs. These differences will matter when we write decoders in Part 3.\nPopular Protocols in the Field #From my experience with GPS tracking in production, these are the protocols and brands you\u0026rsquo;re likely to run into:\nProtocol Common Brands Format Description GT06 Concox, Coban, Xexun, diverse OEMs Binary Most affordable, widest variety of clones Teltonika Teltonika FMB/FMTC/FM Binary Premium tier, solid docs, codec system Meitrack Meitrack MVT/MST Binary Common across enterprise fleet deployments Wialon IPS Various brands (Universal) Text (ASCII) Comma-separated, human-readable format H02 H02/GPS103 Text (ASCII) Simple, common in budget trackers MQTT Modern multi-sensor hardware JSON over MQTT Emerging trend: 4G hardware pushing JSON Binary vs. Text Protocols #GPS protocols fall into two big camps.\nBinary protocols (Teltonika, GT06, Meitrack):\nEvery byte has a precise meaning, often packing several fields Very bandwidth-efficient (1 byte = 8 bits = 8 independent boolean flags) Harder for humans to read (\\x8e\\x01\\x04 vs. lat=-6.2,lng=106.8) Needs thorough vendor documentation to parse correctly Text protocols (Wialon, H02):\nDirectly readable ASCII strings: #L#359769030123456;NA Easy to debug in plaintext logs Higher bandwidth footprint Good for quick prototyping or low-resource devices The Trend: MQTT and JSON #Lately I\u0026rsquo;ve started running into newer trackers (4G/LTE, Cat-M1, NB-IoT) that use MQTT with JSON payloads. A payload can look like this:\n{ \u0026#34;imei\u0026#34;: \u0026#34;359769030123456\u0026#34;, \u0026#34;lat\u0026#34;: -6.2, \u0026#34;lng\u0026#34;: 106.816666, \u0026#34;speed\u0026#34;: 42, \u0026#34;course\u0026#34;: 180, \u0026#34;ignition\u0026#34;: true, \u0026#34;timestamp\u0026#34;: \u0026#34;2026-09-08T10:30:00Z\u0026#34; } JSON is easier to parse, human-readable, and doesn\u0026rsquo;t need a special low-level protocol spec. But in Indonesia 2G/3G devices are still common and still use binary TCP. Both approaches will probably live side by side for the next few years.\nMisconceptions I Learned the Hard Way #\u0026ldquo;Reading one vendor\u0026rsquo;s documentation is enough\u0026rdquo; #Wrong. GT06 has dozens of protocol variations because countless white-label OEM clones tweaked small framing details. Concox GT06, Coban GPS103, and \u0026ldquo;generic GT06\u0026rdquo; have subtle differences that will crash your parser if you don\u0026rsquo;t handle those edge cases.\n\u0026ldquo;IMEIs are always unique per device\u0026rdquo; #In theory, yes. In practice, cheap clone hardware can ship with duplicate or invalid IMEIs. Give your database its own surrogate device_id primary key, and don\u0026rsquo;t use raw IMEIs as primary keys without normalization.\n\u0026ldquo;An active TCP connection means the tracker is online\u0026rdquo; #Not always. NAT table drops, silent carrier-level resets, and frozen devices can leave a socket looking alive on the server while the device has been dead for hours. That\u0026rsquo;s why heartbeat/keep-alive timeouts are a must.\n\u0026ldquo;Every tracker reports timestamps in UTC\u0026rdquo; #Most do, but some brands send timestamps in local time (such as UTC+7 for Indonesia). Check the protocol spec, or better, don\u0026rsquo;t assume and test with a real device.\nTools for Packet Inspection #Before writing a decoder, I \u0026ldquo;peek\u0026rdquo; at the incoming traffic first with a few tools.\n1. TCP Packet Logger #To see packet structure, use a simple TCP connection handler that logs incoming bytes. This example only receives and prints data; it does not forward anything to another server:\n// Minimal TCP logger: dump all inbound bytes func handleConn(conn net.Conn) { defer conn.Close() buf := make([]byte, 1024) for { n, err := conn.Read(buf) if err != nil { break } fmt.Printf(\u0026#34;%x\\n\u0026#34;, buf[:n]) // print as hex } } Hex dumps make it easier to compare packet layouts with vendor datasheets.\n2. Wireshark #If you can capture traffic on the server interface, filter Wireshark by tcp.port == 5094 (or your listening port) to inspect each packet. \u0026ldquo;Follow TCP Stream\u0026rdquo; shows the full conversation between tracker and server.\n3. Device Simulators #Some vendors provide simulators. If yours doesn\u0026rsquo;t, record packets from a physical tracker and replay them in tests. That way you don\u0026rsquo;t need a physical device every time you work on a decoder for another protocol.\nWhat to Have in Your Head Before Moving On #Before moving on, make sure you\u0026rsquo;ve got these:\nWhy GPS devices use TCP sockets rather than HTTP: bandwidth efficiency, persistent connections, and control over the format Device-to-server lifecycle: connect → login → data reporting → commands → heartbeat Binary packet anatomy: start marker, length, payload, CRC, end marker Protocol differences per brand: binary vs. text, GT06 vs. Teltonika vs. MQTT Common gotchas: duplicated IMEIs, TCP \u0026ldquo;alive\u0026rdquo; but device dead, inconsistent timezones What\u0026rsquo;s Next #This article is part of the Building a GPS Backend from Scratch series.\nNext up: Part 2: Building a High-Performance GPS TCP Listener in Go, where we build a TCP server that handles hundreds of tracker connections concurrently with goroutines.\nIf you want to jump straight to reading packets, Part 3 covers the details of parsing GT06 and Teltonika binary frames.\nFor questions or discussion, head to Contact or subscribe to RSS.\n","canonical":"https://najib.id/en/writing/2026/memahami-gps-protocol/","description":"GPS trackers send location data over TCP sockets using binary protocols that differ per brand. My notes on how it works, the packet formats of Teltonika and GT06, and why not HTTP.","language":"en","lastmod":"2026-11-11T23:31:00Z","publishedAt":"2026-09-08T00:00:00Z","readingTime":10,"section":"writing","series":["gps-backend-series"],"tags":["gps","iot","tcp","networking"],"title":"Understanding GPS Protocols: How Tracker Devices Communicate","type":"writing","url":"https://najib.id/en/writing/2026/memahami-gps-protocol/","wordCount":1945}
