Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4540414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:04:58+00:00 2026-05-21T15:04:58+00:00

I have just bought a GPS Tracker, it can send SMS to cellphone just

  • 0

I have just bought a GPS Tracker, it can send SMS to cellphone just fine. It also supports reporting to a server via GPRS.

I have setup the device to contact my own server on port 8123, it’s a FreeBSD server and i have checked that i recieve packets on that port.

I successfully have setup a listener server written in PHP, and i can receive data from the device. But how do i convert the partial HEX data to something usefull (ASCII)?

Example data string:

$$^@T^@E Y'^WÿU210104.000,A,5534.4079,N,01146.2510,E,0.00,,170411,,*10|1.0|72|0000á

Unfortunately i don’t know how i can copy-paste the HEX parts

Now how do i get the ID part out? I have tried echo hexdec(mb_substr($data, 4, 7));

The data is following this protocol

From the document:

Command format of GPRS packets are as follows:

From server to tracker:
@@\r\n 

From tracker to server: 
$$\r\n

Note: 
Do NOT input ‘’ when writing a command. 
All multi-byte data complies with the following sequence: High byte prior to low byte. 
The size of a GPRS packet (including data) is about 100 bytes

Item        Specification
@@          2 bytes. It means the header of packet from server to tracker. 
            It is in ASCII code (Hex code: 0x40)

$$          2 bytes. It is the header of packet from tracker to server.
            It is in ASCII code (Hex code: 0x24)

L           2 bytes. It means the length of the whole packet including 
            the header and ending character and it is in hex code

ID          7 bytes, ID must be digit and not over 14 digits, the unused byte 
            will be stuffed by ‘f’ or ‘0xff’. It is in the format of hex code.
            For example, if ID is 13612345678, then it will be shown as 
            follows: 0x13, 0x61, 0x23, 0x45, 0x67, 0x8f, 0xff.
            If all 7 bytes are 0xff, it is a broadcasting command. ID is in hex code

command     2 bytes. The command code is in hex code. Please refer to the 
            command list below.

data        Min 0 byte and max 100 bytes. See Annex 1 for description of ‘data’.

checksum    2 bytes. It indicates CRC-CCITT (default is 0xffff) checksum of
            all data (not including CRC itself and the ending character).
            It is in hex code. 
            For example: 24 24 00 11 13 61 23 45 67 8f ff 50 00 05 d8 0d 0a
            0x05d8 = CRC-CCITT (24 24 00 11 13 61 23 45 67 8f ff 50 00)

\r\n        2 bytes. It is the ending character and in hex code 
            (0x0d,0x0a in hex code)

Update

With the answer from Anomie, i was able to piece this together

$arr = unpack('H4length/H14id/H4cmd/H4crc/H4end', mb_substr($data, 2, 11) . mb_substr($data, -4));

var_dump($arr);

This will out put something like

array(5) {
  ["length"]=>
  string(4) "0054"
  ["id"]=>
  string(14) "004512345678ff"
  ["cmd"]=>
  string(4) "9955"
  ["crc"]=>
  string(4) "c97e"
  ["end"]=>
  string(4) "0d0a"
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:04:59+00:00Added an answer on May 21, 2026 at 3:04 pm

    It sounds like you are needing to convert binary data to integers or strings. The most straightforward way is to use unpack.

    For example, to extract the length you already know you can use

    $length_bin = substr($string, 2, 2);
    

    To convert it to an integer, you can use something like

    $length = unpack('v', $length_bin); $length = $length[1];
    

    The 'v' code will work for the length and the checksum; if you have a number stored as 4 bytes use 'V', and for the ID you can use 'H*' to get it as a string of hex digits. Other codes are listed in the documentation.


    A somewhat less straightforward way is to do the bit manipulation manually, after using unpack with C* to get an array of all the byte values. For example,

    $bytes = unpack('C*', $length_bin);
    $length = ($bytes[0] << 8) | $bytes[1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just bought a new Windows server with IIS on it and plesk
I have just bought a Wacom Bamboo touch tablet. It works fine with all
I have just bought a VPS running Ubuntu and I need to install the
I have a neural network written in Erlang, and I just bought a GeForce
i have just bought 12 bluetooth dongles and they all have the same mac
I have a wordpress site at http://myname.myprovider.info and I just bought the domain http://www.myname.com
Does anyone know where I can find one? [Update] I have bought many SIM
I have just bought FlashFirebug Pro, so I am able to run ActionScript at
I mainly do .Net development but have just bought an Apple Mac Book Pro
I just bought Visual Studio 2008 Professional and it came with SQL Server 2005

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.