1

Im trying to build a small GPS-tracking software.

To parse the data sent through TCP/IP from the device to my server I am using this package: https://github.com/uro/teltonika-fm-parser

I already receive all necessary information and store it to the database successfully.

But unfortunately, the FMB965 sends the same records again and again. So, after I've formatted the tracker, it start's with one record. Next connection two records, etc. etc. Seems like the ACK doesn't get back to the tracker?

    $ip = env('SOCKET_SERVER_IP');
    $port = env('SOCKET_SERVER_PORT');

    $parser = new FmParser('tcp');
    $socket = stream_socket_server("tcp://$ip:$port", $errno, $errstr);
    $this->info("Listening to tcp://{$ip}:{$port}...");
    if (!$socket) {
        throw new \Exception("$errstr ($errno)");
    } else {
        while ($conn = stream_socket_accept($socket)) {

            // Read IMEI
            $payload = fread($conn, 1024);
            $imei = $parser->decodeImei($payload);

            // Accept packet
            fwrite($conn, Reply::accept());

            // Read Data
            $payload="";
            while( !feof( $conn ) ) {
                $payload .= fread( $conn, 1024 ) ;
            }

            $packet = $parser->decodeData($payload);

            fwrite($conn, $parser->encodeAcknowledge($packet));

            foreach ($packet->getAvlDataCollection()->getAvlData() as $avlData) {
                $gps = $avlData->getGpsElement();
                // Create it in DB
                $this->info('Record created');
            }
            fclose($conn);
        }

        fclose($socket);
    }
rakete
  • 2,953
  • 11
  • 54
  • 108
  • Did you consider to ignore duplicated records? Or extend between-send period when location stay the same? – Tomasz Ferfecki Jul 12 '22 at 10:10
  • @TomaszFerfecki That’s not possible. That would mean, that after a few hours maybe hundreds or thousands records got send per round. This will use too much data. And this ACK stuff seems to be a built in feature. I should get this working. – rakete Jul 12 '22 at 19:38
  • Your question presumes knowledge of how a FMB965 works and what library you're using (e.g. what is `Reply` class? `FmParser`?) You should [edit] your question to include a [mre], rather than rely on external links to explain things. – miken32 Jul 12 '22 at 22:20
  • Can you confirm that your device is in TCP mode and not UDP which doesn't need an ACK? https://wiki.teltonika-gps.com/view/FMB965_GPRS_settings – Chris Haas Jul 15 '22 at 17:31
  • @ChrisHaas Yes, double checked it. It's in TCP mode. – rakete Jul 15 '22 at 22:32
  • Okay, thanks, that was then “cross your fingers and hope you get lucky” attempt. I see similar posts recently in various places which I assume is you, and if so, can you update the question with those references? If someone somewhere is able to help you, maybe by linking others might be able to solve this in the future. If I had such a device I’d try to debug further, but you are doing everything according to the docs as far as I can see, so that’s as far as I can help. Good luck with this! – Chris Haas Jul 16 '22 at 02:02

0 Answers0