Platform
Commands & Control

Commands & Control

Commands let you send instructions from the Plexus dashboard to a connected device and see results in real time. The dashboard auto-generates UI controls (sliders, dropdowns, toggles) from the command schema you define in your agent code.

How It Works

  1. Your device registers commands with the Python agent, including parameter schemas
  2. The dashboard reads those schemas and renders appropriate input controls
  3. You fill in the parameters and click Execute
  4. The command is sent over WebSocket to the device
  5. The device executes the command and returns a result
  6. The dashboard displays the result

Commands travel through the PartyKit WebSocket server, so your device must be connected via plexus run (not HTTP-only mode).

Defining Commands

Define commands in your Python agent using the @px.command decorator:

from plexus import Plexus, param
 
px = Plexus()
 
@px.command("set_speed", description="Set motor speed")
@param("rpm", type="float", min=0, max=10000, unit="rpm")
async def set_speed(rpm):
    motor.set_rpm(rpm)
    return {"actual_rpm": motor.read_rpm()}
 
@px.command("set_mode", description="Set operating mode")
@param("mode", type="enum", options=["idle", "run", "calibrate"])
async def set_mode(mode):
    controller.set_mode(mode)
    return {"mode": mode, "status": "ok"}
 
@px.command("toggle_led", description="Toggle status LED")
@param("enabled", type="bool")
async def toggle_led(enabled):
    gpio.write(LED_PIN, enabled)
    return {"led": enabled}

Auto-Generated UI

The dashboard generates input controls based on parameter types:

Parameter TypeUI Control
float / intSlider (when min/max defined) or number input
boolToggle switch
enumDropdown selector
stringText input

When you provide min, max, and unit metadata, the slider shows the range and unit label.

Executing Commands

From the dashboard:

  1. Navigate to your device's detail page
  2. Open the Commands tab
  3. Select a command from the list
  4. Set the parameter values using the generated controls
  5. Click Execute

The result appears below the command form once the device responds. If the command takes time to complete, a progress indicator shows the execution status.

Execution Status

StatusDescription
PendingCommand sent, waiting for device to acknowledge
RunningDevice is executing the command
CompletedCommand finished, result available
FailedCommand raised an error on the device
TimeoutDevice did not respond within 30 seconds
CancelledCommand was cancelled from the dashboard

Command History

Every command execution is logged. View the history from the Commands tab on the device page. Each entry shows:

  • Command name and parameters
  • Execution timestamp
  • Duration
  • Status and result (or error message)

Error Handling

If a command raises an exception on the device, the error is sent back to the dashboard:

@px.command("self_test", description="Run hardware self-test")
async def self_test():
    result = hardware.run_diagnostics()
    if not result.passed:
        raise Exception(f"Self-test failed: {result.reason}")
    return {"status": "passed", "duration_ms": result.duration}

The dashboard displays the error message in the result area.

Next Steps