Bug in teltonika decoder?

Pavle3 years ago

Hy,
We are trying to manipulate data directly from tc_positions table, but the thing is we need the data in order by fixtime.
The issue is that the data coming from our teltonika devices comes in chronological order and sometimes contains multiple position records like in this raw example.

00000000000000f2080300000180cd538712000a64d84d19a8c8fb000e00e8150000f00c05ef01f001150545010101024236f518000003f10000558dc70000000010008689ad020b000000d14675f3600e0000000003cc262d00000180cd538af0000a64da3019a8ca8c000f0002150008000c05ef01f001150545010101024236f218000803f10000558dc70000000410008689b1020b000000d14675f3600e0000000003cc262d00000180cd538ed8000a64da2019a8cb64000f015e140009fa0d06ef01f001150545010101fa01024236fb18000903f10000558dc70000000010008689b1020b000000d14675f3600e0000000003cc262d0300002c7f

The thing is when we manually decode this we get positions in correct order (chronologically)
Time stamps when we manualy decode:

{
  timeStamp: 1652712245010,
  priority: 0,
  longitude: 174381133,
  latitude: 430491899,
  altitude: 14,
  angle: 232,
  satellites: 21,
  speed: 0,
  HDOP: 0,
  ignition: 1,
  powerVoltage: 14069,
  IOs: [
    { num: 239, value: 1, hex: '01' },
    { num: 240, value: 1, hex: '01' },
    { num: 21, value: 5, hex: '05' },
    { num: 69, value: 1, hex: '01' },
    { num: 1, value: 1, hex: '01' },
    { num: 66, value: 14069, hex: '36f5' },
    { num: 24, value: 0, hex: '0000' },
    { num: 241, value: 21901, hex: '0000558d' },
    { num: 199, value: 0, hex: '00000000' },
    { num: 16, value: 8817069, hex: '008689ad' },
    { num: 11, value: 898830300000, hex: '000000d14675f360' },
    { num: 14, value: 63710765, hex: '0000000003cc262d' }
  ]
}
{
  timeStamp: 1652712246000,
  priority: 0,
  longitude: 174381616,
  latitude: 430492300,
  altitude: 15,
  angle: 2,
  satellites: 21,
  speed: 8,
  HDOP: 0,
  ignition: 1,
  powerVoltage: 14066,
  IOs: [
    { num: 239, value: 1, hex: '01' },
    { num: 240, value: 1, hex: '01' },
    { num: 21, value: 5, hex: '05' },
    { num: 69, value: 1, hex: '01' },
    { num: 1, value: 1, hex: '01' },
    { num: 66, value: 14066, hex: '36f2' },
    { num: 24, value: 8, hex: '0008' },
    { num: 241, value: 21901, hex: '0000558d' },
    { num: 199, value: 4, hex: '00000004' },
    { num: 16, value: 8817073, hex: '008689b1' },
    { num: 11, value: 898830300000, hex: '000000d14675f360' },
    { num: 14, value: 63710765, hex: '0000000003cc262d' }
  ]
}
{
  timeStamp: 1652712247000,
  priority: 0,
  longitude: 174381600,
  latitude: 430492516,
  altitude: 15,
  angle: 350,
  satellites: 20,
  speed: 9,
  HDOP: 0,
  ignition: 1,
  powerVoltage: 14075,
  IOs: [
    { num: 239, value: 1, hex: '01' },
    { num: 240, value: 1, hex: '01' },
    { num: 21, value: 5, hex: '05' },
    { num: 69, value: 1, hex: '01' },
    { num: 1, value: 1, hex: '01' },
    { num: 250, value: 1, hex: '01' },
    { num: 66, value: 14075, hex: '36fb' },
    { num: 24, value: 9, hex: '0009' },
    { num: 241, value: 21901, hex: '0000558d' },
    { num: 199, value: 0, hex: '00000000' },
    { num: 16, value: 8817073, hex: '008689b1' },
    { num: 11, value: 898830300000, hex: '000000d14675f360' },
    { num: 14, value: 63710765, hex: '0000000003cc262d' }
  ]
}

But in the database in tc_positions they are saved in some random order
See the positions with server time 14:44:11

| ID | PROTOCOL | | SERVERTIME | FIXTIME
| ------------- |:-------------:|| ------------- |:-------------:|
| 48060898 | teltonika | 760 | 2022-05-16 14:44:02 |2022-05-16 14:43:59|
| 48060906 | teltonika | 760 | 2022-05-16 14:44:04 |2022-05-16 14:44:01|
| 48060923 | teltonika | 760 | 2022-05-16 14:44:08 |2022-05-16 14:44:05|
| 48060930 | teltonika | 760 | 2022-05-16 14:44:11 |2022-05-16 14:44:07| <-
| 48060931 | teltonika | 760 | 2022-05-16 14:44:11 |2022-05-16 14:44:06| <-
| 48060932 | teltonika | 760 | 2022-05-16 14:44:11 |2022-05-16 14:44:05| <-
| 48060962 | teltonika | 760 | 2022-05-16 14:44:18 |2022-05-16 14:44:14|
| 48060977 | teltonika | 760 | 2022-05-16 14:44:22 |2022-05-16 14:44:17|
| 48061031 | teltonika | 760 | 2022-05-16 14:44:29 |2022-05-16 14:44:26|

Usually, data arrives in the correct order as seen from records before and after.
In this case, the order of the records is the exact opposite but we have multiple cases where there isn't a particular order.

So is this a bug or does the traccar/teltonika decoder work on multiple threads when it gets a message with multiple records and doesn't care for order, or am i missing something other.
If this is the expected behaviour is there a way to force the decoder to save them in tc_positions in the order they arived since it seems that the decoder takes the message with multiple records and decodes the frame and then handles the records and saves them to tc_position in some randomn order.

If you need me to provide more info/data im more than happy to do so.

Anton Tananaev3 years ago

Do you have geocoding enabled?

Pavle3 years ago

Thank you for your response,
Yes, it seems that geocoding was the culprit.
We disabled it and all positions are saved chronologically. We'll handle the geocoding another way.