CURL code for TCP command

GPS-911 2 years ago

Hi,

how do you send TCP messages to a device with H02 protocol using CURL with API? Does anyone know the correct CURL command for this?

Anton Tananaev 2 years ago

Probably ChatGPT can give you a ready to use command. But if you just want to see what you need to send, check what the official app sends. It uses the same API.

GPS-911 2 years ago

Just need to send custom commands like FREQ,123456,600
Or Interval,123456,600

I am able to send from through custom command feature but wants to send commands with cronjob like updating devices reportig time at night.

Chatgpt is not smart yet to get traccar send tco message:p

GPS-911 2 years ago

I anyone need in future are working CURL code

 curl -X POST -H "Content-Type: application/json" -u "youremail@domain.com:your_traccar_password" -d '{
  "id": 11,
  "attributes": {
    "data": "CQ"
  },
  "deviceId": 10,
  "type": "custom",
  "textChannel": false,
  "description": "Reboot"
}' https://example.com/api/commands/send
GPS-911 2 years ago

@Anton Tananaev can you remove my website url from the code please

Anton Tananaev 2 years ago

Removed

GPS-911 2 years ago

Here's a functional PowerShell CURL script tested on Windows 11.

ID is your saved command ID
DeviceID is your device ID

$uri = "https://example.com/api/commands/send"
$headers = @{
    "Content-Type" = "application/json"
    "Authorization" = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("youremail@domainmail.com:yourpassword"))
}

$body = @{
    id = 11
    attributes = @{
        data = "CQ"
    }
    deviceId = 10
    type = "custom"
    textChannel = $false
    description = "Reboot"
} | ConvertTo-Json

Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body