Well, if you link all devices to your user you will get all the events.
Ok, thanks. The Idea was to get all events and send Telegram notifications to the "owner" of the event. So I'll solve this with multiple instances of the websocket listener for the Moment and if I get more clients, maybe I'll do a direct integration into the server.
You might want to use event forwarding:
Ah, that sounds good... but somehow, I don't get much data in the POST... I was following
this post.
traccar.xml:
<entry key='event.forward.enable'>true</entry>
<entry key='event.forward.url'>http://localhost/traccar/event.php</entry>
<entry key='event.forward.header'>
content-type: application/json
cache-control: no-cache
</entry>
<entry key='forward.enable'>true</entry>
<entry key='forward.url'>http://localhost/traccar/position.php</entry>
event.php:
<?php
$log_dir = '/tmp/';
$log_name = "posts-" . $_SERVER['REMOTE_ADDR'] . "-" . date("Y-m-d-H") . ".log";
$log_entry = gmdate('r') . "\t" . $_SERVER['REQUEST_URI'] . "\n\tpost: " . serialize($_POST) . "\n\ttype: " . $_POST['event']['type'] . PHP_EOL;
$fp=fopen( $log_dir . $log_name, 'a' );
fputs($fp, $log_entry);
fclose($fp);
?>
Result (pressing SOS on Android client):
Mon, 15 May 2017 13:21:22 +0000 /traccar/event.php
post: a:0:{}
type:
Hello eiten,
Here is what I have done in my php file, if this helps you.
<?php
$request_body = file_get_contents('php://input');
$data = json_decode($request_body);
$type = $data->{'event'}->{'type'};
$serverTime = convertUTCToIST($data->{'event'}->{'serverTime'});
$deviceName = $data->{'device'}->{'name'};
$alarmType = $data->{'event'}->{'attributes'};
$alarmTypeReturn = $alarmType->{'alarm'};
$deviceId = $data->{'event'}->{'deviceId'};
$geofenceId = $data->{'event'}->{'geofenceId'};
?>
You can further build, and customize this to your requirement. ensure the event forwarder is pointing to the php with the above code.
Hello Nefretiti,
cool, that works perfectly! Thanks! I understood that the data is forwarded as POST data.
HTH, Edi
Hello jaimzj , I will implement the line as below
traccar.xml
<entry key='event.forward.enable'>true</entry>
<entry key='event.forward.url'>http://localhost/traccar/event.php</entry>
<entry key='event.forward.header'>
content-type: application/json
cache-control: no-cache
</entry>
I don't have any devices on the Traccar server, developing devices. I have only Traccar Android for server test communication. Do you have an example data log to send and see if it works? Is forwarded event data includes GPS location info?
event.php
<?php
$request_body = file_get_contents('php://input');
$data = json_decode($request_body);
$type = $data->{'event'}->{'type'};
$serverTime = convertUTCToIST($data->{'event'}->{'serverTime'});
$deviceName = $data->{'device'}->{'name'};
$alarmType = $data->{'event'}->{'attributes'};
$alarmTypeReturn = $alarmType->{'alarm'};
$deviceId = $data->{'event'}->{'deviceId'};
$geofenceId = $data->{'event'}->{'geofenceId'};
?>
Hello,
is there a possibility to access all events over websockets? I mean not only the events for a user, but the events for all users?
Thanks, Edi