# Commands

> Send RPC commands to devices and inspect delivery state in the console or API.

Commands allow backend services to request device-side actions. In Infuse-IoT Cloud, command workflows are represented by RPC messages.

Use RPC when a backend integration needs to trigger device behavior, request a reading, update runtime behavior, or invoke another command supported by the device firmware.

## Commands In The Console

Open **Infuse IoT** > **Commands** to dispatch a manual RPC. You can use:

<table>
<thead>
  <tr>
    <th>
      Mode
    </th>
    
    <th>
      Use
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Guided
    </td>
    
    <td>
      Enter device ID, command name or command ID, optional timeout values, string params, and optional encoded params.
    </td>
  </tr>
  
  <tr>
    <td>
      Raw JSON
    </td>
    
    <td>
      Provide the command request body directly.
    </td>
  </tr>
</tbody>
</table>

You can also open a device, select **RPCs**, and dispatch a command with the device ID prefilled.

The console validates that:

- device ID is a 16-character hex string,
- either command name or command ID is provided,
- command ID is at most `65535`,
- timeout values are non-negative integers,
- send wait timeout is at most `86400000` milliseconds.

After dispatch, open the RPC detail page to inspect status, request params, response payload, downlink message details, and target device context.

## RPC Flow

1. Confirm the target device exists with `GET /device/deviceId/{deviceId}`.
2. Check state or last route if your command requires the device to have communicated recently.
3. Build the RPC request using the active RPC definitions for the device firmware.
4. Send the RPC with `POST /rpc`.
5. Store the returned RPC message ID.
6. Poll or read the message with `GET /rpc/{id}` to inspect delivery and response state.

## Wait Timeout And Route Reuse

`POST /rpc` accepts a `sendWaitTimeoutMs` value. If it is `0` or omitted, Infuse-IoT Cloud sends the RPC immediately using the device's last known route. If it is set to a positive value, Infuse-IoT Cloud can wait for the device to send a packet before attempting the downlink.

Choose the timeout based on your device's power and connectivity model:

<table>
<thead>
  <tr>
    <th>
      Device model
    </th>
    
    <th>
      Recommended behavior
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Always connected
    </td>
    
    <td>
      Send immediately or use a short wait.
    </td>
  </tr>
  
  <tr>
    <td>
      Low-power periodic wake
    </td>
    
    <td>
      Use a wait timeout aligned with the expected wake interval.
    </td>
  </tr>
  
  <tr>
    <td>
      Intermittent or field devices
    </td>
    
    <td>
      Read last route and state before queuing operationally important commands.
    </td>
  </tr>
</tbody>
</table>

## Definition-Driven Commands

RPC definitions describe the commands, structs, and enums used to encode and decode RPC payloads. Keep backend command builders aligned with the device firmware version and the definitions registered in Infuse-IoT Cloud.

Use [Definitions](/docs/infuse-iot-cloud/definitions) to understand the RPC definition registry.

## Useful Endpoints

<table>
<thead>
  <tr>
    <th>
      Task
    </th>
    
    <th>
      Endpoint
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      List RPC messages
    </td>
    
    <td>
      <code>
        GET /rpc
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Send an RPC
    </td>
    
    <td>
      <code>
        POST /rpc
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Read one RPC message
    </td>
    
    <td>
      <code>
        GET /rpc/{id}
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Get latest RPC definitions
    </td>
    
    <td>
      <code>
        GET /defs/rpc
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Get RPC definitions by version
    </td>
    
    <td>
      <code>
        GET /defs/rpc/{version}
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Add RPC definition version
    </td>
    
    <td>
      <code>
        POST /defs/rpc
      </code>
    </td>
  </tr>
</tbody>
</table>

For exact request and response schemas, see the [Infuse-IoT Cloud API reference](/api-reference/iot).
