Teltonika and handling of out-of-order records

Kaldek 21 hours ago

Context first: We have code we can submit as a PR here to resolve the issue below.

Teltonika trackers can be configured to send records with High Priority. Must customers (including us) use this feature to force the tracker to send records outside of the normal reporting interval, or to wake a tracker from sleep (and also send a record). However, if a teltonika tracker has no mobile signal, it will store all of its records in a local cache (100MB, basically 12 months+ worth). When a mobile signal is re-obtained, the tracker will upload all high priority records first, and then all normal/low priority records.

The following Claude-generated diagram visualises the issue.
Out-of-order backlog flow-traccar.png

Before we submit a PR, is this even considered a problem? If not, we will apply it to our systems only.

Here's a summary of what the PR does:

  • BacklogHandler.java (new code we add) runs just before DistanceHandler. When a record's fix time is earlier than the newest cached record, it notes the time for that device.
  • BacklogRecomputeManager.java (also new) waits until no late records have come from that device for 60 s. Then it reads the stored records in fix-time order, 6 hours at a time, so a backlog of weeks is fine. For each record it recomputes distance, totalDistance, hours, and any processing.copyAttributes value that a computed attribute sets, which covers Immobiliser. It saves only the rows that change, then updates the live state and the web clients.
  • Live data is never held back
Anton Tananaev 20 hours ago

Why not just disable priority?

Kaldek 19 hours ago

Can't do it on the tracker. We need a means of ensuring certain events force the tracker to send a record immediately, and the only way to do that on teltonika is to mark the setting as "High Priority". For example, we need it to immediately send record if ignition state changes, or when the movement flag goes to 0.

There's no setting on Teltonika for "connect immediately, but don't treat it as high priority". One and both are the same.

Anton Tananaev 19 hours ago

Does Teltonika have any flag to say when history finished uploading?

Kaldek 18 hours ago

That's an excellent question, and one I'll go dig into. Bear with me while I do that.

Kaldek 18 hours ago

OK, checked and confirmed via Teltonika Wiki on their Data Sending Protocols that no, there is no flag for this.
https://wiki.teltonika-gps.com/view/Teltonika_Data_Sending_Protocols

We also have a support ticket from Teltonika directly where they confirmed the above.

Anton Tananaev 10 hours ago

Do you already have your solution implemented?