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&timestamp={fixTime}&lat={latitude}&lon={longitude}&speed={speed}</entry>
The error is that you hardcoded the id instead of using a placeholder.
Greetings, I'm testing with .........5055/?id={864035050730150}&times,........
do you mean this?
I mean {uniqueId}
instead of hardcoding your device id.
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?
Forwarding is global. You can't select specific devices.
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}&timestamp={fixTime}&lat={latitude}&lon={longitude}&speed={speed}</entry>
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: &batt={batteryLevel}&charge={charge}
Adding batteryLevel
and charge
functionality to forward.url
seems not that easy...
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));
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)))
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&timestamp={fixTime}&lat={latitude}&lon={longitude}&speed={speed}>