Softlab Relay Server - Official Documentation

Welcome to the Softlab Relay Server API! This platform provides ultra-low latency, bidirectional WebSocket communication designed specifically for remote hardware automation (e.g., controlling a Raspberry Pi via a PC/Bot).

1. Connection Details

All clients (both Commanders and Workers) connect to the same central endpoint. The server handles routing messages between clients based on their API keys and target IDs.

2. Authentication Handshake

Security is enforced at the connection level. You cannot send commands until you complete the authentication handshake.

Step 1: Connect & Authenticate

Immediately upon opening the WebSocket connection, the client must send an authentication payload. You can use either a Master API Key (for controllers/bots) or a Device Token (for hardware).

Option A: Master API Key (Requires sender ID)

{
  "auth_key": "YOUR_RAW_MASTER_KEY",
  "sender": "my_controller_id"
}

Option B: Device Token (ID is pre-assigned)

{
  "device_token": "YOUR_DEVICE_TOKEN"
}

Step 2: Await Confirmation

The server verifies the credentials and assigns the socket to a secure, isolated room.

{
  "status": "authenticated",
  "client_id": "my_controller_id"
}
Note: Once authenticated, you do not need to include credentials in subsequent messages.

Step 3: Constraints & Error Handling

The following are default limits. Administrators can increase these on a per-user basis (e.g., for enterprise customers or specialized hardware).

3. The Messaging Contract

Once authenticated, clients can freely pass messages to one another. The relay acts as a blind switchboard—it looks at the target field and forwards the entire JSON payload to that specific client ID.

A. Offline Messaging

If a message is sent to a target that is offline, the server queues it (default capacity is 50 messages and 24-hour TTL, but this can be increased per user). These are delivered upon the target's next login with a "_offline_queued": true flag added to the payload.

B. Sending a Command (Commander ➔ Worker)

{
  "target": "mouse_pi",
  "sender": "tkinter_bot",
  "priority": "highest",
  "speed": 100,
  "subtasks": "Mx1920y1080 / C"
}

4. Presence API (HTTP)

While most communication happens via WebSockets, you can check the real-time status of multiple devices via a standard HTTP GET request. This is primarily used by the dashboard but is available for any authenticated session.

{
  "mouse_pi": "online",
  "sensor_pi": "offline"
}

5. Implementation Best Practices

6. Client Implementation Examples

Choose your preferred programming language to see a minimal implementation for both Commanders and Workers.

Python SDK (Recommended)

For Python developers, we provide a production-ready client wrapper that handles authentication, heartbeats, and reconnection.

Download: relay_client.py

from relay_client import SoftlabRelayClient

def on_data(data):
    print(f"Message received: {data}")

# Commander Example
client = SoftlabRelayClient(
    auth_key="YOUR_MASTER_KEY",
    sender="my_pc",
    on_message=on_data
)
client.start()

# Send a message
client.send_message("mouse_pi", {"command": "move", "x": 100})