TK915 /watch proto keeps bouncing device offline/online

GregoryO7 years ago

Hi,

So I Identified protocol as "watch" then set the right port to the device.
However maybe every second request from device to traccar, device is being treated as offline as NumberFormatException.

trace:

2018-01-02 18:53:56 DEBUG: [AE35098F: 5093 < 94.254.163.68] HEX: 5b53472a393035313036333033322a303037372a55442c3032303131382c3137353335352c412c35322e3037303333382c4e2c32302e3433353236322c452c312e323936342c3030302c342c30352c35302c39302c302c35302c30303030303030302c322c312c3236302c362c313031352c31383630372c3133382c313031352c31323831322c3133322c2c30305d
2018-01-02 18:53:56  INFO: [AE35098F] id: 9051063032, time: 2018-01-02 18:53:55, lat: 52.07034, lon: 20.43526, speed: 0.7, course: 0.0


2018-01-02 18:54:56 DEBUG: [AE35098F: 5093 < 94.254.163.68] HEX: 5b53472a393035313036333033322a303037372a55442c3032303131382c3137353435342c412c35322e3037303334342c4e2c32302e3433353038352c452c302e313438312c3030302c312c30362c35302c39302c302c35302c30303030303030302c322c312c3236302c362c313031352c31383630372c3133362c313031352c31323831322c3133312c2c30305d
2018-01-02 18:54:56  WARN: [AE35098F] error - For input string: "32*0" - NumberFormatException (... < WatchFrameDecoder:37 < ...)
2018-01-02 18:54:56  INFO: [AE35098F] disconnected
2018-01-02 18:54:56  WARN: [AE35098F] error - For input string: "32*0" - NumberFormatException (... < WatchFrameDecoder:37 < ... < MainEventHandler:115 < *:104 < ... < GeocoderHandler:43 < ...)
2018-01-02 18:54:57  INFO: [7B0D455B] connected
2018-01-02 18:55:54  INFO: [7B0D455B] disconnected

2018-01-02 19:03:46 DEBUG: [15EDF80E: 5093 < 94.254.163.120] HEX: 5b53472a393035313036333033322a303030392a4c4b2c302c39305d
2018-01-02 19:03:54 DEBUG: [15EDF80E: 5093 < 94.254.163.120] HEX: 5b53472a393035313036333033322a303037372a55442c3032303131382c3138303334352c412c35322e3037303232312c4e2c32302e3433343439322c452c312e303337312c3030302c302c30372c35302c39302c302c35302c30303030303030302c322c312c3236302c362c313031352c31383630372c3134302c313031352c31323831322c3133322c2c30305d
2018-01-02 19:03:54 DEBUG: [15EDF80E: 5093 > 94.254.163.120] HEX: 5b53472a393035313036333033322a303030322a4c4b5d
2018-01-02 19:03:54  WARN: [15EDF80E] error - For input string: "77*U" - NumberFormatException (... < WatchFrameDecoder:37 < ...)
2018-01-02 19:03:54  INFO: [15EDF80E] disconnected
2018-01-02 19:03:54  WARN: [15EDF80E] error - For input string: "77*U" - NumberFormatException (... < WatchFrameDecoder:37 < ... < MainEventHandler:115 < *:104 < ... < GeocoderHandler:43 < ...)
2018-01-02 19:03:55  INFO: [C889237B] connected

Any idea what I can correct and where ?

I can help with some git pull request in java of that helps. Just need small directions...

BR,
Gregory

Anton Tananaev7 years ago

Your device sends invalid message length:

[SG*9051063032*0009*LK,0,90]

Message length in the example above is reported as 9, but it's clearly less than 9.

GregoryO7 years ago

OK lets take the most recent tracker request from now,
and treat is as main example:

2018-01-02 22:15:35 DEBUG: [E80C5C49: 5093 < 94.254.163.68] HEX: 5b53472a393035313036333033322a303037382a55442c3032303131382c3231313533322c412c35322e3037303332352c4e2c32302e3433343730302c452c302e323539322c3030302c312c30382c38302c3130302c302c35302c30303030303030302c322c312c3236302c362c313031352c31383738312c3133372c313031352c31323831322c3133352c2c30305d
2018-01-02 22:15:35  WARN: [E80C5C49] error - For input string: "32*0" - NumberFormatException (... < WatchFrameDecoder:37 < ...)
2018-01-02 22:15:35  INFO: [E80C5C49] disconnected
2018-01-02 22:15:35  WARN: [E80C5C49] error - For input string: "32*0" - NumberFormatException (... < WatchFrameDecoder:37 < ... < MainEventHandler:115 < *:104 < ... < GeocoderHandler:43 < ...)

Decoded with hex decoder gives:

[SG*9051063032*0078*UD,020118,211532,A,52.070325,N,20.434700,E,0.2592,000,1,08,80,100,0,50,00000000,2,1,260,6,1015,18781,137,1015,12812,135,,00]

is 0078 bad here ?
Look that it wants to parseInt on string "32*" which is few bytes before 0078.

Forum formatter drops "star" in here in log "error - For input string: "32*0" " https://pastebin.com/U4J7mfV5

Anton Tananaev7 years ago

You are looking at the message after invalid one. Obviously at this point nothing would work as previous message was not decoded properly.

GregoryO7 years ago

I dont get it, Is it streaming? Look and longer log here: https://pastebin.com/7MaSrvhN

Sometimes the device sends it ok and sometimes not.

Anton Tananaev7 years ago

Yes, TCP is a streaming protocol. Decoding stop working after a broken message in a stream because server is not able to correctly determine beginning and ending of frames.

GregoryO7 years ago

Can I let it to not treat as offline when message is broken ?
Or do you have an idea what I can correct in the java code ?

My goal is just to not indicate it in UI as offline/online all the time. actually just forget that broken frame.

Anton Tananaev7 years ago

Server closes connection when there is an error, which makes sense. When connection is closed device is displayed as offline which is the definition of "offline" state.

The issue is on the device side, so you don't need to "correct" anything in the server code. You can try to implement some workaround if you want.

GregoryO7 years ago

Anton,

So I couldnt sleep. Took few tcpdumps and it looks like the frame is always[bla*LEN*bla] so instead of frame LEN as encoded in the frame I modified the WatchFrameDecoder.java to look for trailing "]" .

Compiled the server, runs good so far. I can share the patch if you want or submit it github branch, or leave it only for me if you prefer.

Anton Tananaev7 years ago

It worked like that before, but the problem is that Watch-based devices can report binary photo and audio data, which can contain any random characters, including ].

Andy7 years ago

Hi,

Sorry to bump the old thread but I am also trying to use a batch of TK915 devices that use the watch protocol and am encountering the same problem. I have no requirement to use anything other than trackers with my instance so Gregory's patch would be ideal - can either of you share it with me?

Thanks,

Andy

GregoryO7 years ago

Hi Andy,

I will post the patch later for you. Will you be able to compile server?

Andy7 years ago

Perfect, thanks Gregory, I should be good with compiling it.

GregoryO7 years ago

Andy,

so it is simple as just replacing traccar/src/org/traccar/protocol/WatchFrameDecoder.java as in this paste:

https://ghostbin.com/paste/t8tzx

Andy7 years ago

Hi Gregory,

Thanks a lot for your help. I've modified the file by replacing the code with that of the above & compiled + packaged it but am still getting the problem. I'm going to have a proper look & reset the device as I suspect I'm missing something. Thanks again!