Hi every one.
i have built an online fleet management app in php/mysqli successfully. I now have to add a gps device to send lon,lat, speed and so on to online app.
I did some reading on php tcp socket listener, but am not very clear. Do any one have a php code that's able to send and receive data from a GPS?
I need to be pointed in the right dircetion...thx alot.

Dani AI

Generated

Short primer for (and thanks to for the pointer to an NMEA parser): the TK106 family is a mixed bag of vendor/clone protocols. The practical flow is: configure the tracker (APN + server IP:port), run a public TCP/UDP listener on the chosen port, log the raw bytes first, then implement a parser for the device format (many devices send an NMEA GPRMC-like sentence with an imei: tag or use a tkstar/xexun-like packet). Confirm the exact protocol in the device manual. (traccar.org)

Set the tracker’s APN and the server IP/port by SMS (examples: adminip123456 <IP> <port> or APN123456 <apn> — exact commands vary by model). Make sure the server has a public IP (or DDNS) and the router forwards the tracker port to the listening machine. Common ports for clones are 5001/5002 but check the manual. (manualzilla.com)

Run a long‑running PHP CLI socket (do not rely on Apache) and log raw packets so you can identify the bytes to parse. Example minimal listener (save as gps-server.php and run with php gps-server.php):

<?php
$srv = stream_socket_server("tcp://0.0.0.0:5000", $errno, $errstr);
if (!$srv) die("$errstr ($errno)");
while ($conn = @stream_socket_accept($srv)) {
  $data = stream_get_contents($conn);
  file_put_contents('gps_raw.log', date('c')." ".bin2hex($data)." raw: ".$data."\n", FILE_APPEND);
  fclose($conn);
}
?>

Use the PHP streams docs when expanding to nonblocking/multiple clients. Start by searching each raw line for imei: and GPRMC, then convert NMEA lat/lon to decimal. If building a parser is too slow, consider Traccar or Flespi as protocol parsers/forwarders. (php.net)

Troubleshoot by: logging hex + text, testing with nc to the port, verifying APN/GPRS and that the device reports a successful “adminip” reply per the manual.

Recommended Answers

All 4 Replies

Hi,
Some 5 or more years ago, someone from phpclasses.org made a PHP GPS locator. For some reason, I can't find my bookmark for it. Yes that could be done.

okay, I found the link in my inbox. Here is the link for the class. The script might need some upgrades, but that should not be a problem.

thx, taken a look at it

Hi Veedeoo, thanks for the info. It looks like the download is missing one file.

But am abit confused, do i need two mail scripts? Listener.php and receive_socket.php? what and what do i need to receive data from gps to my website?

Pls help out...:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.