/commands API - Response

Atul7 years ago

Hello,

When the /commands API respond to any POST request, its returns with 200 OK with the same POST request i.e. "$ref": "#/definitions/Command"

        "/commands": {
            "post": {
                "summary": "Dispatch commands to device",
                "parameters": [
                    {
             …
                        "schema": {
                            "$ref": "#/definitions/Command"
    …
                "responses": {"200": { "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/Command"
                        }

I have observed that this happens even if its unsuccessfully for any other reason than offline (400). In such cases, user get the wrong information. For example, if user tries to set SOS number using /commands API with "type":"custom" & by sending the command in "attributes":{"data":"[CS6005412902…..]"}, it returns the 200 OK but actually it doesn’t set SOS number on device.

The document at https://www.traccar.org/protocols/ - https://dl.dropboxusercontent.com/s/2hid9vaa2vno4jr/Communication%20Protocol.doc says for every command we send, it returns a “terminal reply”

(1)Set the first SOS number
The platform sending:
[CSYYYYYYYYYYLENSOS1,phone number]
Example:[SG
88000000150010SOS1,00000000000]

The terminal reply:
[CSYYYYYYYYYYLENSOS1]
Example:[SG
88000000150004SOS1] --- > Please note there’s no ‘00000000000’ in terminal reply in above example.

For example - this is what we get in log file (Sorry below log is not for setting SOS)

Sent --> 2017-05-29 11:31:51 DEBUG: [C1FA297D: 5093 > 1.187.20.253] HEX: 5b43532a363030353431323930322a303030372a4d4f4e49544f525d
Decodes to --> [CS60054129020007MONITOR]
Received 2017-05-29 11:31:52 DEBUG: [C1FA297D: 5093 < 1.187.20.253] HEX: 5b33472a363030353431323930322a303030372a4d4f4e49544f525d
Decodes to --> [3G
60054129020007MONITOR]

Please notice “[CS…]” while sending and “[3G…”] in return.

Is it possible to get “The terminal reply” i.e. [3G*…] as a part of 200 OK as response?

Thanks,
Atul

Anton Tananaev7 years ago

That's intended behaviour. Not all devices support responses, so it's not possible to implement universal solution. Instead Traccar has a special "command response" events for the devices that support responses.

Atul7 years ago

What is that I need to get that? this is for 'watch' protocol. In the event documentation, there are 9 different events category, but not sure which one captures 'command response event'

Thanks,
Atul

Anton Tananaev7 years ago

Watch protocol has a very limited support for command results at the moment.

There are more than 9 event categories and one of them is "commandResult".

Atul7 years ago

Thanks Anton.

To enable this do I have to add something like below. This is based on other event handlers from this link - https://www.traccar.org/documentation-events/

 <entry key='event.commandResultHandler'>true</entry>

I can try enabling this and see if it works for my case.

Please let me know.

Thanks,
Atul

Atul7 years ago

Oh infact, documentation says "By default all Events handlers are enabled" - does that mean commandResult is also enabled by default?

If yes, how can I use/test it?

Thanks,
Atul

Anton Tananaev7 years ago

They are enabled on the server, but to receive notifications you also need to enable them for your user account from Settings > Notifications menu.

Agam6 years ago

Hi @Atul, were you able to get the result of the commands. Do i have to configure something to get the result of GPRS commands. I can see the response in the traccar log file but not on the web interface. I have enabled notifications of commandResult but not getting anything.
Will appreciate your help

bsaggarwal5 years ago

HI Agam/Atul/Anton
i am facing the same issue as Agam.
I have configured command result notification as web for my user account..
I could see the response in traccar logs ( hex format) but nothing is displayed on the user web screen.
am i missing any configuration on Traccar 4.2.?

Anton Tananaev5 years ago

It might not be decoded.

bsaggarwal5 years ago

I am able to decide it using hex decoder correctly...what do I need to decode it ?
Its h02 protocol st901 device.

Anton Tananaev5 years ago

You need to implement it in the code.