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.

  • 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-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-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-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