I have tried to forward my all events to another server database but I got error in the console
2022-07-25 20:49:06 WARN: Event forwarding failed - MessageBodyReader not found for media type=text/html;charset=UTF-8, type=class java.lang.Object, genericType=class java.lang.Object. - MessageBodyProviderNotFoundException (...)
traccar.xml
<entry key='event.forward.enable'>true</entry>
<entry key='event.forward.url'>https://mywebsite.com/input.php</entry>
input.php
<?php
$request_body = file_get_contents('php://input');
$data = json_decode($request_body);
$type = $data->{'event'}->{'type'};
$serverTime = $data->{'event'}->{'serverTime'};
$deviceName = $data->{'device'}->{'name'};
$alarmType = $data->{'event'}->{'attributes'};
$alarmTypeReturn = $alarmType->{'alarm'};
$deviceId = $data->{'event'}->{'deviceId'};
$geofenceId = $data->{'event'}->{'geofenceId'};
$servername = "localhost";
$username = "user";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO notifications (type, serverTime, deviceName, alarmType, alarmTypeReturn, deviceId, geofenceId)
VALUES ('$type', '$serverTime', '$deviceName', '$alarmType-', '$alarmTypeReturn', '$deviceId', '$geofenceId')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
You shouldn't send anything back. Or if you're sending, it should be JSON.
This error after updating the PHP code
2022-07-25 21:25:26 WARN: Event forwarding failed - MessageBodyReader not found for media type=text/html;charset=UTF-8, type=class java.lang.Object, genericType=class java.lang.Object. - MessageBodyProviderNotFoundException (...)
input.php (new Code)
<?php
$request_body = file_get_contents('php://input');
$data = json_decode($request_body);
$type = $data->{'event'}->{'type'};
$serverTime = $data->{'event'}->{'serverTime'};
$deviceName = $data->{'device'}->{'name'};
$alarmType = $data->{'event'}->{'attributes'};
$alarmTypeReturn = $alarmType->{'alarm'};
$deviceId = $data->{'event'}->{'deviceId'};
$geofenceId = $data->{'event'}->{'geofenceId'};
$servername = "localhost";
$username = "abc";
$password = "abc";
$dbname = "crm";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "INSERT INTO notifications (type, serverTime, deviceName, alarmType, alarmTypeReturn, deviceId, geofenceId)
VALUES ('$type', '$serverTime', '$deviceName', '$alarmType-', '$alarmTypeReturn', '$deviceId', '$geofenceId')";
$conn->query($sql);
$conn->close();
?>
it's giving an error in the console but the data still receive means working fine Thanks dear great support...!
I have tried to forward my all events to another server database but I got error in the console
traccar.xml
<entry key='event.forward.enable'>true</entry> <entry key='event.forward.url'>https://mywebsite.com/input.php</entry>
input.php
<?php $request_body = file_get_contents('php://input'); $data = json_decode($request_body); $type = $data->{'event'}->{'type'}; $serverTime = $data->{'event'}->{'serverTime'}; $deviceName = $data->{'device'}->{'name'}; $alarmType = $data->{'event'}->{'attributes'}; $alarmTypeReturn = $alarmType->{'alarm'}; $deviceId = $data->{'event'}->{'deviceId'}; $geofenceId = $data->{'event'}->{'geofenceId'}; $servername = "localhost"; $username = "user"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "INSERT INTO notifications (type, serverTime, deviceName, alarmType, alarmTypeReturn, deviceId, geofenceId) VALUES ('$type', '$serverTime', '$deviceName', '$alarmType-', '$alarmTypeReturn', '$deviceId', '$geofenceId')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>