Sending a Raw Command from a Digital Twin Instance

Send a command to a device.

Depending on the type of data you want to send, use the following CLI commands and API operation to send a raw JSON command, a raw plain text command, or a raw binary command to a device.

Note

Currently, MQTT Secure (MQTTS) is only supported using port 8883.

For more information, see Scenario: Receiving Commands and Sending Responses using MQTTs.

    1. On the Domains list page, select the domain that you want to work with. If you need help finding the IoT domains list page or an IoT domain, see Listing IoT Domains.
    2. Select the Digital twin instances tab.
    3. Select the digital twin instance name you want to work with.
    4. From the Actions menu at the top of the page, select Send raw command.
    5. Enter the Request endpoint, the device where the command should be forwarded to.
    6. Enter the Request duration, defines a time frame for the device to complete the command execution. Use ISO 8601 for the duration format, for example PT3M equals 3 minutes.
    7. Select the command data format and enter the command details, the maximum size is 256k:
      • JSON: JSON command data.
      • Binary: Drag and Drop or select a file with the base64 encoded command data. Typically the mime content type is application/octet-stream. You can edit the content type.
      • Plain text: Enter the plain text raw command data.
    8. Optional. Turn on the option to Specify response parameters
      • Response duration: Maximum time the system waits for a response. Use ISO 8601 for the duration format, for example PT3M equals 3 minutes.
      • Response endpoint: Device endpoint where the response is expected, for example, myinstance/response.
    9. Select Send raw command.
  • Use the oci iot digital-twin-instance invoke-raw-<data-type>-command command and required parameters to invoke a raw JSON, binary, or text command on a device. Replace the <digital-twin-instance-OCID> with the digital twin instance OCID for your environment:

    Use the oci iot digital-twin-instance invoke-raw-json-command command to invoke a raw JSON command. Replace the values for your environment:

    oci iot digital-twin-instance invoke-raw-json-command \
      --digital-twin-instance-id <digital-twin-instance-OCID> \
      --request-endpoint /endpoints/<device-id> \
      --request-data '{"temp": 34}' \
      --request-data-content-type application/json \
      --request-duration PT10M \
      --response-endpoint /endpoints/<response-device-id>

    Use the oci iot digital-twin-instance invoke-raw-binary-command command to invoke a raw binary command. Replace the parameter values for your environment:

    oci iot digital-twin-instance invoke-raw-binary-command \
    --digital-twin-instance-id <digital-twin-instance-OCID> \
    --request-endpoint /endpoints/1234 \
    --request-data file:///mnt/data/binary_input.bin \
    --request-data-content-type application/octet-stream \
    --request-duration PT10M 
    --response-endpoint /endpoints/4321

    Use the oci iot digital-twin-instance invoke-raw-text-command command to invoke a raw text command. Replace the parameter values for your environment:

    oci iot digital-twin-instance invoke-raw-text-command \
    --digital-twin-instance-id <digital-twin-instance-OCID> \
    --request-endpoint /endpoints/1234 \
    --request-data 'command input as text' \
    --request-data-content-type text/plain \
    --request-duration PT10M \
    --response-endpoint /endpoints/4321

    For a complete list of parameters and values for CLI commands, see CLI Command Reference.

  • Run the InvokeRawCommand operation and the required parameter to send a raw command to a device. The following data types are supported:
    • JSON
    • binary
    • text

Command Responses

ScenarioDevice StateExpected Command StateComments
Not ConnectedNot connected not subscribed REFUSED Command delivery fails immediately
Connected but not subscribedConnected REFUSEDDevice online but does not receive command
Subscribed but not connected Subscribed onlyPENDING → EXPIREDCommand waits; expires after timeout
Subscribed but not connected initially and gets connected before timeout Initially offline PENDING → SENTCommand Received
Connected and subscribedConnected and Subscribed SENT Command Received
One-Way Command(No response expected)Connected and Subscribed COMPLETED Response is not expected and tracked
Two-Way Command (No response received)Connected and Subscribed NOT_RESPONDEDDevice does not respond within response duration timeout
Two-Way Command (response received) Connected and Subscribed COMPLETEDDevice sends data within response time out and complete the flow