The WebSocket Remote API requires the WS plugin.
- Install required packages for simStubsGen: see simStubsGen's README
- Checkout, compile and install into CoppeliaSim:
$ 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;- (optional)
id
(string) an identifier to correlate request with response.
Example:
{
"func": "sim.getObject",
"args": ["/Floor"]
}
A response is an object with fields:
- (optional)
id
(string) set to the same value of the request'sid
field; success
(boolean)true
if the call succeeded, in which case theret
field will be set, orfalse
if the call failed, in which case theerror
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')"
}