Connection protocol

How a robot talks to the XPARO server. You only need this to write your own client (for a robot without ROS 2, or in another language); xparo_ros does all of it for you.

Connection sequence: WebSocket with secret key, ADD_robots_info, project sync, ROBOT_CREDENTIAL, heartbeat every 30 seconds.

Addresses

Channel

Address

WebSocket

wss://xparo.in/ws/chatbot_api/<key>/<project-id>/

HTTPS

https://xparo.in/chatbot_api/<key>/<project-id>/

<key> is a project secret key for a robot’s first connection, and the robot’s own credential afterwards. There is no separate login: the key in the address is the authentication. A wrong key, and a project ID that doesn’t exist, are both refused during the WebSocket handshake with 403: the socket never opens, so there is no close code. To tell them apart, GET the HTTPS address: an unknown project answers 404 {"error": "Unknown project id: check xparo_project_id."} and a wrong key 403 (see HTTP API).

To keep the key out of URLs (and proxy logs), put _ in its place in the path and send the key in an X-Xparo-Secret header instead. Both addresses accept it.

Messages

Every message, in both directions, is one JSON object whose keys are dispatch keys (the message names listed in Message catalogue), each with its own payload:

{"ROBOT_HEARTBEAT": {"device_id": "my-robot-0001"}}

Usually there is one key, but one object can carry several. The project sync the server sends on connect is a single object with many keys (title, aiml, custom_aiml, custom_tasks, custom_node_files, …), and the reply to ADD_robots_info combines ROBOT_CREDENTIAL, REST_API_TOKEN, sync_local_database and others. Handle every key you know and ignore the rest.

A robot may only send the “robot → server” messages of Message catalogue. Anything else (a dashboard message such as GET_robots_list, an unknown key), a binary frame, or text that isn’t one JSON object is ignored and answered with {"error": "..."} saying why; the WebSocket stays open.

One connection may send up to 2,000 messages in 10 seconds. Past that, the rest of those 10 seconds’ messages are dropped unread (the first one is answered with {"error": "Too many messages: ..."}), and a connection that keeps flooding (20,000 in 10 seconds) is closed with code 4429.

Some server messages are wrapped in a message key, for example answers from the AI assistant:

{"message": {"bot_response": "...", "responded_by": "llm"}}

A robot’s first connection

  1. Open the WebSocket with the project’s secret key. The server sends nothing yet: it doesn’t know which robot you are.

  2. Send ADD_robots_info with the robot’s details (below). Don’t wait for anything first.

  3. If the robot is accepted, the server sends the project sync, then the reply to ADD_robots_info. The first time a device ID is seen, that reply contains ROBOT_CREDENTIAL. Save it and use it instead of the secret key from now on; it is sent only once. If the robot is refused, the reply says why and the socket closes (see When a robot is refused).

  4. Every 30 seconds, send ROBOT_HEARTBEAT (xparo_ros sends it with an HTTPS POST to the HTTPS address). The dashboard shows the robot online while the last heartbeat is less than 90 seconds old.

A connection opened with the robot’s credential gets the project sync straight away, because the server already knows which robot it is. Send ADD_robots_info on every connection anyway.

ADD_robots_info must contain all of these fields, as text: device_id, hostname, os_name, os_version, os_release, mac_address, ip_address, cpu_model, cpu_count, cpu_physical_count, total_memory, available_memory, total_disk, used_disk, free_disk. If any is missing (or null), nothing is registered: the server answers {"error": "ADD_robots_info is missing hostname, ...: the robot was not registered. ..."} (over HTTPS, with status 400). Optional: ros_distro, xparo_git_commit, locations ({"latitude": ..., "longitude": ...}), data (free-form details), width and height (screen size).

The server stores data as the robot sends it and reads two keys from it. Robots on an older xparo_ros send neither, and keep working as before:

  • xparo_stage: development, testing, review or production (the launch’s xparo_stage). The project’s website counts a robot as in service only when it sends production or no stage at all.

  • health: {"stale_keeps_error": true} means the robot keeps a problem active when its component goes silent (STALE), until the component reports OK. Without it, the server treats an inactive error next to an active STALE row for the same component as “went silent, no OK since”, and keeps it in Needs Attention.

device_id identifies the robot: keep it the same across restarts, or the robot appears as a new one.

Dashboard commands (Run now, terminal, teleop, files…) are delivered only to robots that registered over the WebSocket and are connected.

When a robot is refused

The server answers ADD_robots_info with one of these keys, its value a sentence that says what to do, and then closes the WebSocket with code 4403. Don’t reconnect in a fast loop: nothing changes until someone acts on the dashboard.

Key

Why

robot_retired

The robot was retired on Robots Fleet. The Owner can Restore it.

robot_credential_required

This robot has its own credential and connected with the secret key instead (it was reinstalled, or its credential file was deleted). Use the credential, or ask the Owner to press Reset robot sign-in.

robot_serial_in_use

Another machine already holds this device ID (it is online, or has its own credential). Give this one its own device ID, or, if it replaces that machine, ask the Owner to press Reset robot sign-in.

A connection that is already open is also closed with 4403 when the Owner retires the robot or presses Reset robot sign-in for it. Freezing, switching off or deleting a secret key doesn’t close anything: it only stops new robots joining with that key.

xparo_ros logs the server’s sentence. After robot_credential_required it switches back to its saved credential by itself; after robot_retired it keeps checking, and once the Owner restores the robot it signs in again and gets a new credential, without a restart on site.

Retiring a robot or resetting its sign-in also switches off its credential: a connection that uses it is then refused at the handshake (403). Connect with the project’s secret key instead to hear why (or, after Restore or Reset robot sign-in, to be given a new credential); the example below does this.

See Identity, many robots and offline for the whole picture.

A complete minimal client

This Python client registers, keeps its credential, sends heartbeats and answers Teleop. It was run against an XPARO server: it appeared online on Robots Fleet, and a Teleop command from the dashboard reached it and was acknowledged.

"""A minimal XPARO robot client without ROS 2: joins a project, keeps a
heartbeat, and answers Teleop commands from the dashboard."""
import json
import os
import threading
import time

import requests
import websocket

SERVER = "xparo.in"
PROJECT_ID = "<your-project-id>"
SECRET_KEY = "<your-secret-key>"
DEVICE_ID = "my-robot-0001"            # any ID that stays the same for this robot
CREDENTIAL_FILE = "xparo_credential.txt"


use_secret_key = False


def secret():
    # After the first connection, use the robot's own credential.
    if os.path.exists(CREDENTIAL_FILE) and not use_secret_key:
        return open(CREDENTIAL_FILE).read().strip()
    return SECRET_KEY


def send(ws, key, payload):
    ws.send(json.dumps({key: payload}))


ROBOT_INFO = {
    # All of these are required (as text); use real values where you have them.
    "device_id": DEVICE_ID, "hostname": "my-robot",
    "os_name": "Linux", "os_version": "Ubuntu 24.04", "os_release": "6.8",
    "mac_address": "02:00:00:00:00:01", "ip_address": "192.168.1.50",
    "cpu_model": "arm64", "cpu_count": "4", "cpu_physical_count": "4",
    "total_memory": "8 GB", "available_memory": "6 GB",
    "total_disk": "64 GB", "used_disk": "12 GB", "free_disk": "52 GB",
}


REFUSALS = ("robot_retired", "robot_credential_required", "robot_serial_in_use")


def on_open(ws):
    print("connected")
    send(ws, "ADD_robots_info", ROBOT_INFO)   # first, without waiting for anything


def on_message(ws, raw):
    global use_secret_key
    message = json.loads(raw)
    for key, value in message.items():
        if key == "ROBOT_CREDENTIAL":
            open(CREDENTIAL_FILE, "w").write(value)
            use_secret_key = False
            print("got my own credential")
        elif key == "TELEOP":
            print("drive:", value["axes"], value["buttons"])
            send(ws, "TELEOP_ACK", {"success": True})
        elif key == "custom_tasks":
            print("tasks in the project:", len(value))
        elif key in REFUSALS:
            print("refused:", key, "-", value)
            ws.refused = True   # the server closes the socket (4403) next


def on_error(ws, error):
    global use_secret_key
    print("error:", error)
    if getattr(error, "status_code", None) == 403 and not use_secret_key:
        # The credential was switched off (robot retired, or its sign-in
        # reset): the secret key gets the reason, or a new credential.
        use_secret_key = True


def on_close(ws, *args):
    print("disconnected")


def heartbeat():
    while True:
        url = f"https://{SERVER}/chatbot_api/{secret()}/{PROJECT_ID}/"
        requests.post(url, json={"ROBOT_HEARTBEAT": {"device_id": DEVICE_ID}}, timeout=10)
        time.sleep(30)


threading.Thread(target=heartbeat, daemon=True).start()
while True:
    # Build the address on every attempt: once the robot has its own
    # credential, a reconnect with the secret key is refused.
    ws = websocket.WebSocketApp(
        f"wss://{SERVER}/ws/chatbot_api/{secret()}/{PROJECT_ID}/",
        on_open=on_open, on_message=on_message,
        on_error=on_error, on_close=on_close,
    )
    ws.refused = False
    ws.run_forever()
    # Refused: nothing changes until someone acts on the dashboard.
    time.sleep(60 if ws.refused else 5)
pip install websocket-client requests
python3 my_robot.py

Output of the test run (the Teleop came from the dashboard):

connected
tasks in the project: 1
got my own credential
drive: [0.5, 0, 0, 0] [1, 0, 0]

What the dashboard received back:

{"message": {"TELEOP_ACK": {"success": true}}}

Reconnecting

xparo_ros reconnects 5 seconds after a drop and re-syncs. While attempts keep failing (no network, or the handshake refused) it doubles the wait each time, up to once a minute, and drops back to 5 seconds after a connection that opens. If its saved credential is refused (the robot was deleted from the project, for example), it connects once more with the secret key it was started with, which registers it again; the credential file is kept and replaced only when the server sends a new credential. Messages that must not be lost (task results and task history) are kept in memory while offline and sent after reconnecting, so a restart while offline loses them (see Identity, many robots and offline).

Connection types

xparo_ros can also poll over HTTPS instead of keeping a WebSocket open (xparo_connection_type): rest polls only; hybrid uses the WebSocket and falls back to polling every 2 seconds during an outage of more than about 25 seconds. In polling mode the robot syncs and reports, but dashboard commands cannot reach it. See Configuration.