WebSocket Service

WARNING

This feature will be deprecated

ws://10.20.17.1/ws/public

The WebSocket service also runs on port 80. Both request and response data are serialized as JSON string byte streams, encoded in UTF-8.

After establishing a WebSocket connection, the robot will periodically push robot status and position information. Developers can implement robot status monitoring by parsing the pushed data.

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

Request ParameterTypeDescription
idintAfter sending the operation command to the server, the corresponding result will be pushed asynchronously to the client. Different requests can be distinguished by id. The id needs to be generated by the user, and the server returns it unchanged
cmdstringRobot command
dataobjectRobot command request parameters
Response ParameterTypeDescription
idintAfter sending the operation command to the server, the corresponding result will be pushed asynchronously to the client. Different requests can be distinguished by id. The id needs to be generated by the user, and the server returns it unchanged
cmdstringRobot command
dataobjectRobot command request parameters
codeintResult code 0: indicates success, others indicate 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))