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.
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-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/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-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 |