This repository is object oriented library to translate Teltonika protocols.
You could use this library in your server, it will help you talk with Teltonika devices.
It was build with Teltonika protocols v2.10 documentation.
{
"require": {
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
}
}
$parser = new FmParser('tcp');
// Decode IMEI
$imei = $parser->decodeImei($payload);
// Decode Data Packet
$packet = $parser->decodeData($payload);
$parser = new FmParser('tcp');
$socket = stream_socket_server("tcp://0.0.0.0:8043", $errno, $errstr);
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());
// Decline packet
// fwrite($conn, Reply::reject());
// Read Data
$payload = fread($conn, 1024);
$packet = $parser->decodeData($payload);
// Send acknowledge
fwrite($conn, $parser->encodeAcknowledge($packet));
// Close connection
fclose($conn);
}
fclose($socket);
}
}