forward.url

ubiteca year ago

Greetings, try this function with the idea of showing the gps 864035050730150 from server 1 on server 2, the result is that it not only sends the data from 864035050730150 but also resends the data from all the gps (another 5 on server 1) and this It shows up on server 2 all together as 864035050730150 so it's jumping from one place to another, the original data is through port 5001, do you have any idea where I have the error? thank you

<entry key='forward.enable'>true</entry>
<entry key='forward.json'>false</entry>
<entry key='forward.url'>http://111.222.333.444:5055/?id=864035050730150&amp;timestamp={fixTime}&amp;lat={latitude}&amp;lon={longitude}&amp;speed={speed}>
ubiteca year ago

copy-paste error on the previous message sorry

   <entry key='forward.enable'>true</entry>
   <entry key='forward.json'>false</entry>
   <entry key='forward.url'>http://111.222.333.444:5055/?id=864035050730150&amp;timestamp={fixTime}&amp;lat={latitude}&amp;lon={longitude}&amp;speed={speed}</entry>
Anton Tananaeva year ago

The error is that you hardcoded the id instead of using a placeholder.

ubiteca year ago

Greetings, I'm testing with .........5055/?id={864035050730150}&amp;times,........ do you mean this?

Anton Tananaeva year ago

I mean {uniqueId} instead of hardcoding your device id.

ubiteca year ago

Excellent and thank you very much, that works perfectly, but one question, from what I see it sends EVERYTHING to server 2. Is there a way to only send the id that you want? Wouldn't it cause extra resource consumption in the vps in the long run if the number of vehicles increases and I still want to send only one on server 2?

Anton Tananaeva year ago

Forwarding is global. You can't select specific devices.

Adama year ago

For anyone looking this is the latest file location
https://github.com/traccar/traccar/blob/master/src/main/java/org/traccar/forward/PositionForwarderUrl.java

                .replace("{name}", URLEncoder.encode(device.getName(), StandardCharsets.UTF_8)) 
                 .replace("{uniqueId}", device.getUniqueId()) 
                 .replace("{status}", device.getStatus()) 
                 .replace("{deviceId}", String.valueOf(position.getDeviceId())) 
                 .replace("{protocol}", String.valueOf(position.getProtocol())) 
                 .replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime())) 
                 .replace("{fixTime}", String.valueOf(position.getFixTime().getTime())) 
                 .replace("{valid}", String.valueOf(position.getValid())) 
                 .replace("{latitude}", String.valueOf(position.getLatitude())) 
                 .replace("{longitude}", String.valueOf(position.getLongitude())) 
                 .replace("{altitude}", String.valueOf(position.getAltitude())) 
                 .replace("{speed}", String.valueOf(position.getSpeed())) 
                 .replace("{course}", String.valueOf(position.getCourse())) 
                 .replace("{accuracy}", String.valueOf(position.getAccuracy())) 
                 .replace("{statusCode}", calculateStatus(position));
<!-- transmit in Osmand protocol -->
<entry key='forward.enable'>true</entry>
<entry key='forward.json'>false</entry>
<entry key='forward.url'>http://<SECONDARY_URL>:5055/?id={uniqueId}&amp;timestamp={fixTime}&amp;lat={latitude}&amp;lon={longitude}&amp;speed={speed}</entry>
Willem Hellenthal10 months ago

Thanks, I was looking for such.

Now I know where I can extend this. Just need to edit this PositionForwarderUrl.java file.

Because I miss batteryLevel and charge. Both did give an error, but that's because it's not in the list yet. And those are attributes supported by Osmand protocol. And those are important information too I find.

After editing the PositionForwarderUrl.java file we can add to url.formward: &amp;batt={batteryLevel}&amp;charge={charge}

Willem Hellenthal10 months ago

Adding batteryLevel and charge functionality to forward.url seems not that easy...

Willem Hellenthal10 months ago

Think i have found the solution to add batteryLevel and charge;

String request = url
                .replace("{name}", URLEncoder.encode(device.getName(), StandardCharsets.UTF_8))
                .replace("{uniqueId}", device.getUniqueId())
                .replace("{status}", device.getStatus())
                .replace("{deviceId}", String.valueOf(position.getDeviceId()))
                .replace("{protocol}", String.valueOf(position.getProtocol()))
                .replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime()))
                .replace("{fixTime}", String.valueOf(position.getFixTime().getTime()))
                .replace("{valid}", String.valueOf(position.getValid()))
                .replace("{latitude}", String.valueOf(position.getLatitude()))
                .replace("{longitude}", String.valueOf(position.getLongitude()))
                .replace("{altitude}", String.valueOf(position.getAltitude()))
                .replace("{speed}", String.valueOf(position.getSpeed()))
                .replace("{course}", String.valueOf(position.getCourse()))
                .replace("{accuracy}", String.valueOf(position.getAccuracy()))
                .replace("{batteryLevel}", String.valueOf(position.getAttributes().get(Position.KEY_BATTERY_LEVEL)))
                .replace("{charge}", String.valueOf(position.getAttributes().get(Position.KEY_CHARGE)))
                .replace("{statusCode}", calculateStatus(position));
Willem Hellenthal10 months ago

And I have tested it, it works with;

.replace("{batteryLevel}", String.valueOf(position.getAttributes().get(Position.KEY_BATTERY_LEVEL)))
.replace("{charge}", String.valueOf(position.getAttributes().get(Position.KEY_CHARGE)))