forward data

Adrien2 years ago

hi,
i would like to transfer the data received by traccar to a web server hosted on my machine

   <!-- begin forward  -->
    <entry key='forward.enable'>true</entry>
    <entry key='forward.json'>true</entry>
    <entry key='forward.url'>http://localhost/xxx/listener.php</entry>
    <!-- end forward  -->

I have the following error :

WARN: Position forwarding failed: 0 pending - Status code 2xx expected - RuntimeException (WebDataHandler:261 < *:186 < ...)

here is the content of my listener.php file

<?php
ob_start();
echo "OK";
header("Content-length: " . (string)ob_get_length());
ob_end_flush();

chdir('../');


$data = json_decode(file_get_contents("php://input"), true);

error_log("data from traccar : " . $data);

?>

what to do? I receive the data from the GPS boxes very well

thnaks

Anton Tananaev2 years ago

Seems like your script is not returning a success code. I don't know PHP, so can't help with that, but it doesn't look like there's any issues with Traccar.

Adrien2 years ago

hi,
we have managed to read the data sent by Traccar in our PHP application. is it possible to configure it to send data to multiple URLs?
thanks

Anton Tananaev2 years ago

No.

Webgeniusa year ago

@Adrien,
I run similar issue with you, checking traccar log I have this errors:

Position forwarding failed: 279 pending - Connection refused: connect - ConnectException (...)

which makes me loose some data or in worse cases no data is sent to my database, while on traccar frontend the device is updating normally and fine.
I am using traccar data forwarding as per below traccar.xml config

<entry key='forward.enable'>true</entry>
<entry key='forward.json'>true</entry>
<entry key='forward.retry.enable'>true</entry>
<entry key='forward.url'>http://localhost/traccar/listener_tcp.php?uniqueId={uniqueId}&amp;deviceId={deviceId}&amp;gprmc={gprmc}&amp;protocol={protocol}&amp;deviceTime={deviceTime}&amp;fixTime={fixTime}&amp;valid={valid}&amp;latitude={latitude}

And running WAMP server on a Windows server 2016
below is snippet of my traccar.php file

<?php
    ob_start();
    header("Content-length: " . (string)ob_get_length());
    ob_end_flush();
    chdir('../');

    $data = $_GET;	
    $loc = $data;
    // check if data comes packaged
    if (!isset($loc["uniqueId"]))
    {
        echo "ok";
    }else
    {
            $loc["imei"] = $loc['uniqueId'];
            $loc['lat'] = (double)sprintf('%0.6f', $loc['latitude']);
            $loc['lng'] = (double)sprintf('%0.6f', $loc['longitude']);
            $loc['angle'] = floor($loc['course']);
            $loc['dt_tracker'] = date('Y-m-d H:i:s', $loc['deviceTime'] / 1000);
            $loc['loc_valid'] = 1;
            $loc['net_protocol'] = $loc['protocol'];
                        $loc['ip'] = "127.0.0.1";
                        $loc['port'] = 5001;
    
            $loc['dt_server'] = gmdate("Y-m-d H:i:s");
            $loc['params'] = (array)json_decode(stripslashes($loc['attributes']));
        
            if (@$loc["op"] == "loc")
                        {
                          insert_db_loc($loc);	
                       }

currently I receive data on db but there are some missing data due to error above, Do you experience same issue and how can this be solved?