Problem http://myserver/api/commands/send and relay not working

rozali5 years ago

Can anyone help me,
I have a problem with using the API from Traccar (linux debian 9 and version traccar 64-4.5) especially /api/commands/send with the POST type. I use javascript and jquery to turn on or turn off the relay. Example of my program:

var u1 = "user";
     var p1 = "password";
var param2 = "{" attributes ": {}," description ":" RELAY, 1 # "," deviceId ": 123456," id ": 0," type ":" engineStop "} ';

               $ .ajax ({
                           type: "POST",
                           url: "http: //myserver/api/commands/send",
                           data: param2,
                           success: function (results) {
var json_obj = results;
                                 alert (JSON.stringify (json_obj));
                           },
                           xhrFields: {
                                           withCredentials: true
                                        },
                           crossDomain: true,
                           error: function (XMLHttpRequest, textStatus, errorThrown) {
                                          alert (textStatus, errorThrown);
                                          console.log (errorThrown);
                                  },
                           beforeSend: function (xhr) {
                                          xhr.setRequestHeader ("Authorization", "Basic" + btoa (u1 + ":" + p1));
                                       },
                           dataType: 'json',
                           contentType: 'application / json'
                 });

and the results I got from the program above are as below:

{"id": 0, "attributes": {}, "deviceId": 353701093737845, "type": "engineStop", "textChannel": false, "description": "RELAY, 1 #"}
But the relay I installed didn't work (I used a yellow and positive cable). If i using web application traccar is working.
Please help me