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.
Currently, MQTT Secure (MQTTS) is only supported using port
8883.For more information, see Scenario: Receiving Commands and Sending Responses using MQTTs.
- 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.
- Select the Digital twin instances tab.
- Select the digital twin instance name you want to work with.
- From the Actions menu at the top of the page, select Send raw command.
- Enter the Request endpoint, the device where the command should be forwarded to.
- 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.
- 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.
- 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.
- Select Send raw command.
Use the
oci iot digital-twin-instance invoke-raw-<data-type>-commandcommand 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/4321Use 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/4321For 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
| Scenario | Device State | Expected Command State | Comments |
|---|---|---|---|
| Not Connected | Not connected not subscribed | REFUSED | Command delivery fails immediately |
| Connected but not subscribed | Connected | REFUSED | Device online but does not receive command |
| Subscribed but not connected | Subscribed only | PENDING → EXPIRED | Command waits; expires after timeout |
| Subscribed but not connected initially and gets connected before timeout | Initially offline | PENDING → SENT | Command Received |
| Connected and subscribed | Connected 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_RESPONDED | Device does not respond within response duration timeout |
| Two-Way Command (response received) | Connected and Subscribed | COMPLETED | Device sends data within response time out and complete the flow |