WebSocket Service

WARNING

This feature will be deprecated soon.

ws://10.20.17.1/ws/public

The WebSocket service also runs on port 80. Both requests and responses are serialized into JSON string byte streams, encoded in UTF-8.

Once a WebSocket connection is established, the robot pushes robot status and position information at a certain frequency. Developers can monitor the robot status by parsing the pushed data.

Developers can directly send commandsopen in new window and wait for the execution result to be pushed. The id in the pushed execution result matches the one sent, so developers can implement their own request/response mechanism.

Request ParameterTypeDescription
idintAfter an operation command is sent to the server, the corresponding result is asynchronously pushed to the client. The id can be used to distinguish different requests. The id needs to be generated by the user, the server just returns it as-is.
cmdstringRobot command
dataobjectRobot command request parameters
Response ParameterTypeDescription
idintAfter an operation command is sent to the server, the corresponding result is asynchronously pushed to the client. The id can be used to distinguish different requests. The id needs to be generated by the user, the server just returns it as-is.
cmdstringRobot command
dataobjectRobot command request parameters
codeintResult code. 0 means success, any other value means failure.

Browser code example:

let ws = new WebSocket('ws://10.20.17.1/ws/public')

ws.onmessage = function(res) {
    let { code, id, cmd, data } = JSON.parse(res.data)
    console.log(code, id, cmd, data)
}

let req = {
    "id": 1,
    "cmd": "movej",
    "data": {
        "pose_to": [0, 0, 0, 0, 0, 0],
        "is_joint_angle": true,
        "acceleration": 1,
        "velocity": 2
    }
}

ws.send(JSON.stringify(req))