PHP code example of diam4ik / teltonika-fm-parser

1. Go to this page and download the library: Download diam4ik/teltonika-fm-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

diam4ik / teltonika-fm-parser example snippets


// Recieve data from tcp socket
$payloadFromDevice = "000F313233343536373839303132333435";

// Decode recieved data
$decoder = new TcpDecoder();

// Check if data which we recieved are authentication or Gps records
if($decoder->isAuthentication($payloadFromDevice)){ // returns true;
    
    $imei = $decoder->decodeAuthentication($payloadFromDevice);
    echo json_encode(imei);
    
    // Check if device is authenticated in your system, and then encode response for device
    $encoder = new TcpEncoder();
    $payload = $encoder->encodeAuthentication(true); // Yes, device was authenticated successfully

    // send $payload though the socket.
}

// Now we need to wait for next data from the device

// Recieve next payload from the socket (now with data)
$tcpPayloadFromDevice = "00000000000000FE080400000113fc208dff000f14f650209cca80006f...";

// Decode it
$data = $this->decoder->decodeData($payload);

echo json_encode(data);