That can happen if your device sends data out of order.
Does it means that device last position rely on time of position being parsed by protocol decoded instead of time reported by device (fixtime)?
Thank you.
It is not directly based on it, but it's based on the order of received positions.
I want to add, that another reason is multi-threading.
If two packets comes in almost same time, they can be parsed in different threads in parallel.
Both threads will use same lastPosition for reference (distance calculation, events generating and so on).
My both test devices using teltonika protocol and none of them got the correct distance in reports.
However if I calculate the sum of distance attributes for the same set of positions - the results are correct.
What I am doing wrong?
I am not the software engineer, so my approach could be incorrect.
But maybe it will be better if lastPosition setter call will determine last device position according to fixtime?
I think it could be a method that executes a single query. Also it seems there is the device cache that should be updated as well.
Teltonika is one of the devices that can upload positions in wrong order or in batches. Traccar does not recalculate distance every time, it's calculated once when server receives data from device.
Hi,
Sometimes totalDistance attribute is calculated wrong.
Please take a look at attributes of three sequential positions:
20308 fixtime: 2016-12-16 23:36:35
{"priority":0,"sat":9,"event":0,"ignition":true,"io22":1,"battery":9360,
"power":28124,"io24":78,"distance":128,"ip":"","totalDistance":6244514.41}
20309 fixtime: 2016-12-16 23:37:00
{"priority":0,"sat":10,"event":0,"ignition":true,"io22":1,"battery":9360,
"power":28071,"io24":70,"distance":508,"ip":"","totalDistance":6245022.41}
20310 fixtime: 2016-12-16 23:37:05
{"priority":0,"sat":11,"event":0,"ignition":true,"io22":1,"battery":9360,
"power":28139,"io24":70,"distance":98,"ip":"","totalDistance":6244612.41}
In position id 20309 totalDistance calculated correctly, but in position id 20310 totalDistance difference is negative -410 instead of 98.
I have done some logging and as you can see the problem arises sometimes:
Looks like the positions are stored correctly according to fixtime.
If I have followed the logic correctly - "distance" value of current position is added to totalDistance of position returned by getLastPosition() which is last position from device table.
So could it be that last position in device table is stored incorrectly? Or this is not the cause?
Thank you.