Forwarding positions for individual devices

Vitek3 years ago

Hi, I found way how to forward incomming GPS data from one server to anothe server.
But it seems that it forward all incoming traffic.

Is it possible to "filter" forwarding just for one ID?
I mean forwarding just one car.

Anton Tananaev3 years ago

There's not way to do it, but you should be able to filter it in your external service if you want.

Vitek3 years ago

Comapny1 server is not allowed to share all data (private cars) with Company2/secondary server, so this scenario is not useable.
But thanks for answear!

Anton Tananaev3 years ago

Who said that filtering should happen on the second server? It can be done before passing it to the other server.

Vitek3 years ago

You mean something like Traccar will forward all to ~127.0.0.1/filter.php , which I script to forward data to second server, if ID is right?
Is that the "external service" what you mentioned?
Thanks

Anton Tananaev3 years ago

Yes, something like that.

Vitek2 months ago

Inspiration for another users, how I solve it:

<?php
/*
traccar.xml:
<entry key='forward.enable'>true</entry>
<entry key='forward.url'>http://your_url.ltd/traccarproxy/?id={uniqueId}&amp;lat={latitude}&amp;lon={longitude}&amp;timestamp={deviceTime}&amp;hdop={accuracy}&amp;alt={altitude}&amp;speed={speed}</entry>
*/

//validity check
if (isset($_GET['id']) && isset($_GET['lat']) && isset($_GET['lon'])) {
  $id = $_GET['id'];
  $lat = $_GET['lat'];
  $lon = $_GET['lon'];
  $alt = $_GET['alt'];
  if ($alt < 1) $alt="1";
  $timestamp = $_GET['timestamp'];
  $hdop = $_GET['hdop'];
  $speed = $_GET['speed'];
  
  
if ($id == '728666554') // Car1
  {
  $targetUrl = "http://url.ltd/get/?latitude={$lat}&longitude={$lon}&altitude={$alt}&id={$id}";
  $content = file_get_contents($targetUrl);    
  exit();
  }

if ($id == '780111222') // Car2
  {
  $targetUrl = "http://url.ltd/get/?latitude={$lat}&longitude={$lon}&altitude={$alt}&id={$id}";
  $content = file_get_contents($targetUrl);    
  exit();
  }    

}
?>