Skip to main content

WebSocket Usage

WebSocket communication uses JSON as data format.

Socket endpoints are:

  • wss://[device]/api/ws for encrypted connections
  • ws://[device]/api/ws for unencrypted connections
note

Encrypted connections require a valid HTTPS certificate for the device.

General Data Structure

Transmission data is formatted in JSON.

Requests

Messages from client to server generally have the following values:

{"msgID":1, "method":""}
  • msgID (optional) can be any value and will be returned by the device to uniquely assign responses to requests.
  • method (required) tells the device what to do.

Every other value depends on the selected method.


Responses

Messages from server to client generally have the following values:

{"msgID":1, "method":""}

Every other value depends on the selected method, as specified.


Methods

The following methods are supported

Required after connecting to the WebSocket to authenticate the connection. Without a valid authentication, no other commands will be accepted. Also required when reconnecting.

Request:

{"msgID":1, "method":"auth", "token":"XYZ"}

Answer:

{"msgID":1, "method":"auth", "token":"XYZ", "success": "true"}
  • token` (required): DHD token

Error handling

Control API is designed to be fault tolerant. If errors occur, the messages will be formatted the following way:

Failed authentication:

{"msgID":1, "method":"auth", "token":"XYZ", "success": "false", "error": {"code":-32002, "message": "invalid token"}}

Socket Timeout

Control API WebSocket connections time out after 60 seconds of inactivity. Any data transmission on the socket will reset that inactivity timer. We recommend sending a heartbeat, such as the WebSocket Pings and Pongs control frame at least every 30 seconds. The console will respond with the according pong. Read more on websocket pings and pongs here.