ReferenceREST API

Control

REST API: Control leases. Generated from the OpenAPI document.

Who controls the robot

GET /v1/control

none, a brain on the MessagePack API, or a REST lease. Send your Nao-Lease header to learn whether it is yours.

Token: required · Lease: not needed

StatusMeaningBody
200Who controls the robotControlStatus
401Missing or wrong tokenErrorBody
curl -H "Authorization: Bearer $TOKEN" http://$ROBOT:7702/v1/control

Take control

POST /v1/control

Returns a lease id for the Nao-Lease header of every command. Keep it with a heartbeat at least every 100 ms; the robot stands after 0.5 s of silence, sits after 3 s, and the lease ends after 10 s. The robot starts with no motion commanded. Fails while a brain is connected.

Token: required · Lease: not needed

Request body (application/json)

AcquireRequest

FieldTypeRequiredMeaning
clientstringyesWho is asking (shown in status and logs), 1 to 64 printable characters. (example joystick-app)
takeoverbooleannoReplace another client's lease. Never replaces a connected brain.
{"client":"joystick-app"}
StatusMeaningBody
201You control the robot now; it starts with no motionLeaseGrant
409A brain is connected (brain_connected) or another client holds the lease (lease_held)ErrorBody
422Invalid inputErrorBody
curl -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"client": "my-script"}' http://$ROBOT:7702/v1/control

Give control back

DELETE /v1/control

The robot then behaves as when a brain disconnects: it stands, then sits.

Token: required · Lease: required (Nao-Lease header)

StatusMeaningBody
204Released; the robot stands, then sits, as when a brain disconnects
409Not the active leaseErrorBody
428No Nao-Lease headerErrorBody
curl -X DELETE -H "Authorization: Bearer $TOKEN" -H "Nao-Lease: $LEASE" http://$ROBOT:7702/v1/control

Keep control

POST /v1/control/heartbeat

Any command counts as a heartbeat too.

Token: required · Lease: required (Nao-Lease header)

StatusMeaningBody
204Still in control
409Not the active leaseErrorBody
428No Nao-Lease headerErrorBody
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Nao-Lease: $LEASE" http://$ROBOT:7702/v1/control/heartbeat

Control over a WebSocket

GET /v1/control/ws

Upgrade to a WebSocket (browsers pass the token as ?access_token=). Send hello first; the socket then holds the lease until it closes. Messages are WsClientMessage (client to robot) and WsServerMessage (robot to client) as JSON text. Send something at least every 100 ms: the robot stands after 0.5 s of silence and sits after 3 s, as with any controller. The messages are on WsClientMessage and WsServerMessage.

Token: required · Lease: not needed

StatusMeaningBody
101Switching to the WebSocket protocol
401Missing or wrong tokenErrorBody
503Too many streams openErrorBody
# With websocat (https://github.com/vi/websocat); type the three lines after connecting.
websocat "ws://$ROBOT:7702/v1/control/ws?access_token=$TOKEN"
{"type": "hello", "client": "pad", "id": 1}
{"type": "leds", "group": "eyes", "setting": {"color": "#0050ff"}, "id": 2}
{"type": "volume", "volume": {"percent": 40}, "id": 3}

On this page