h02 protocol - sos malfunctioning

Khaksar3 years ago

Hello everyone,
From bellow log, I get a SOS event for each log-row (for each hex/binary data), while according to our device's manufacturer documentation, the SOS would be from the 1st bit of bitmask (the same which is implemented in Traccar), but I can see in the Status field of position in Traccar-UI that the bitmask is normal for all records and it is (4294967295). I also tested the standard SOS functionality of the device and it is working as expected, I mean, if there is SOS reported, it shows the bitmask as 4294967293 and Traccar also includes it in Position attributes and generate an event for it.

From Web-UI, in Notifications and Notification Type Alarm, only SOS is added and enabled for mentioned device.

So, I didn't get how Traccar generates SOS from this data?

2022-01-25 16:28:01  INFO: [b6ed8db4: h02 < device_ip] HEX: 2a48512c343930303131323439372c56312c3135323830302c412c353131332e373432322c4e2c30303634322e363132392c452c3030342e32302c3032352c32
2022-01-25 16:28:01  INFO: [b6ed8db4: h02 < device_ip] HEX: 35303132322c46464646464646462c3236322c312c31333630312c36333233342c3223
2022-01-25 16:28:01  INFO: [b6ed8db4: h02 > device_ip] HEX: 2a48512c343930303131323439372c56342c56312c323032323031323531353238303123
2022-01-25 16:28:35  INFO: [b6ed8db4: h02 < device_ip] HEX: 2449001124971528272501225113725002006425928e000190ffffffffff001724000012370106010000000003dc53
2022-01-25 16:28:35  INFO: [b6ed8db4] id: device_id, time: 1999-11-30 07:01:00, lat: 5.39204, lon: -1.20829, speed: 282.0, course: 725.0
2022-01-25 16:28:45  INFO: [b6ed8db4: h02 < device_ip] HEX: 2449001124971528372501225113726002006425929e000347ffffffffff001724000012370106010000000003d954
2022-01-25 16:28:45  INFO: [b6ed8db4] id: device_id, time: 1999-11-30 07:01:00, lat: 5.37554, lon: -1.20829, speed: 283.0, course: 725.0
2022-01-25 16:28:55  INFO: [b6ed8db4: h02 < device_ip] HEX: 2449001124971528472501225113725902006425939e000048ffffffffff001724000012370106010000000003db55
2022-01-25 16:28:55  INFO: [b6ed8db4] id: device_id, time: 1999-11-30 07:01:00, lat: 5.32571, lon: -1.20829, speed: 284.0, course: 725.0
2022-01-25 16:29:05  INFO: [b6ed8db4: h02 < device_ip] HEX: 2449001124971528572501225113725202006425931e000357ffffffffff001724000012370106010000000003d956
2022-01-25 16:29:05  INFO: [b6ed8db4] id: device_id, time: 1999-11-30 07:01:00, lat: 5.35921, lon: -1.20829, speed: 285.0, course: 725.0
2022-01-25 16:29:15  INFO: [b6ed8db4: h02 < device_ip] HEX: 2449001124971529072501225113726502006425940e000039ffffffffff001724000012370106010000000003da57
2022-01-25 16:29:15  INFO: [b6ed8db4] id: device_id, time: 1999-11-30 07:01:00, lat: 5.32604, lon: -1.20829, speed: 290.0, course: 725.0
2022-01-25 16:29:25  INFO: [b6ed8db4: h02 < device_ip] HEX: 2449001124971529172501225113728002006425916e000002ffffffffff001714000012370106010000000003ca58
2022-01-25 16:29:25  INFO: [b6ed8db4] id: device_id, time: 1999-11-30 07:01:00, lat: 5.34287, lon: -1.20829, speed: 291.0, course: 725.0

Any idea that what I missing or what goes wrong?

Anton Tananaev3 years ago

You should check the source code to see which bit we are checking.

Khaksar3 years ago

It is the same, bit 1.

Anton Tananaev3 years ago

And you are saying that the alarm is generated even if the bit is not set? It doesn't add up.

Khaksar3 years ago

Yes, the bit is not set and alarm is generated. But for the bitmask, I am looking into the Status attribute of the position in Web-UI, I see it is not set for the SOS.

Khaksar3 years ago

What I see in this log is the wrong date, location, speed and course. It means the reported location is invalid, but still don't know how Traccar is generating SOS from this? Any hint to test it with source code, how I can pass this data (which I received from device) to my local development instance? to debug and see how it is being interpreted and why Traccar sending the notification.

Khaksar3 years ago

I am still struggling but no idea yet, any help will be appreciated.

I can explain the issue a little bit more as bellow:

  1. The traccar decode the hex correctly while the device reports it by GPS, but when I put the tracker inside the room and it is trying to report it with WiFi, then this issue comes in.

  2. I tried to manually assign the deviceId to longId in H02ProtocolDecoder, with ByteBufUtil.hexDump(buf.readSlice(8)).substring(0, 15); but that didn't help and all records filtered out as future.

  3. Here is the protocol documention from device manufacturer, I see a little difference in the hex length with those already implemented in H02.

  4. I tried to log the ByteBuff in H02ProtocolDecoder, I see the log results was a bit different with valid and invalid hex.

Valid Hex:
2022-01-26 14:44:10  INFO: [284680c8: h02 < 80.187.102.186] HEX: 2449001124971344002601225113750001006426475e002050ffffffffff001322000012380106010000000003d331
2022-01-26 14:44:10  INFO: ByteBuff: PooledSlicedByteBuf(ridx: 0, widx: 32, cap: 32/32, unwrapped: PooledDirectByteBuf(ridx: 32, widx: 47, cap: 64))
2022-01-26 14:44:10  INFO: [284680c8] id: 4900112497, time: 2022-01-26 14:44:00, lat: 51.22917, lon: 6.71079, speed: 2.0, course: 50.0
Invalid Hex:
2022-01-26 14:00:32  INFO: [363eff39: h02 < 80.187.118.126] HEX: 2449001124971300302601225113715701006425818e001021ffffffffff001425000012380106010000000003bed4
2022-01-26 14:00:32  INFO: ByteBuff: PooledSlicedByteBuf(ridx: 0, widx: 32, cap: 32/32, unwrapped: PooledDirectByteBuf(ridx: 64, widx: 94, cap: 128))
2022-01-26 14:00:32  INFO: [363eff39] id: 4900112497, time: 1999-11-30 07:01:00, lat: -5.18887, lon: -1.20829, speed: 3.0, course: 26.0

Even, if I translate above invalid parsed data manually, I will see the right date, while traccar parsed it invalid!
Manually extraction according to documentation: 24 4900112497 13:00:30 26-01-22 51137157 01 006425818e 0010 21 ffffffffff 001425000012380106010000000003bed4.
5. I tried to test the hex accross the unit tests, but it failed with bellow messages:

expected: UnpooledHeapByteBuf(ridx: 0, widx: 47, cap: 47/47) but was:UnpooledSlicedByteBuf(ridx: 0, widx: 32, cap: 32/32, unwrapped: UnpooledHeapByteBuf(ridx: 32, widx: 47, cap: 47/47))
Expected: UnpooledHeapByteBuf(ridx: 0, widx: 47, cap: 47/47)
Actual: UnpooledSlicedByteBuf(ridx: 0, widx: 32, cap: 32/32, unwrapped: UnpooledHeapByteBuf(ridx: 32, widx: 47, cap: 47/47))
java.lang.AssertionError: expected: UnpooledHeapByteBuf(ridx: 0, widx: 47, cap: 47/47)  but was: UnpooledSlicedByteBuf(ridx: 0, widx: 32, cap: 32/32, unwrapped: UnpooledHeapByteBuf(ridx: 32, widx: 47, cap: 47/47))
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.traccar.protocol.H02FrameDecoderTest.testDecodeShort(H02FrameDecoderTest.java:19)

I am using latest traccar v14.5 as traccar server version.

Any help will be appreciated...

Anton Tananaev3 years ago

That's probably related to the message length. This issue has been discussed before.

Khaksar3 years ago

I confirm that the issue was because of message length, the message length in my case was 47 which was different than the default one.

adding <entry key='h02.messageLength'>47</entry> solved the issue.

Thank you @Anton for your help.