The WebSocket Remote API requires the WS plugin.
$ git clone https://github.com/CoppeliaRobotics/wsRemoteApi
$ cd wsRemoteApi
$ git checkout coppeliasim-v4.5.0-rev0
$ mkdir -p build && cd build
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ cmake --build .
$ cmake --install .
NOTE: replace coppeliasim-v4.5.0-rev0
with the actual CoppeliaSim version you have.
Connect WebSocket to the endpoint (by default on port 23050), send a message (see request below), and read the response (see response below). The request and response can be serialized to JSON or CBOR. The response will be serialized using the same serialization format used in the request.
See also the example client example.html
.
A request is an object with fields:
func
(string) the function name to call;args
(array) the arguments to the function;id
(string) an identifier to correlate request with response.Example:
{
"func": "sim.getObject",
"args": ["/Floor"]
}
A response is an object with fields:
id
(string) set to the same value of the request's id
field;success
(boolean) true
if the call succeeded, in which case the ret
field will be set, or false
if the call failed, in which case the error
field will be set;ret
(array) the return values of the function;error
(string) the error message.Example:
{
"success": true,
"ret": [37]
}
In case of error, the exception message will be present:
{
"success": false,
"error": "Object does not exist. (in function 'sim.getObject')"
}