az iot device

Leverage device-to-cloud and cloud-to-device messaging capabilities.

Commands

az iot device c2d-message

Cloud-to-device messaging commands.

az iot device c2d-message abandon

Abandon a cloud-to-device message.

az iot device c2d-message complete

Complete a cloud-to-device message.

az iot device c2d-message receive

Receive a cloud-to-device message.

az iot device c2d-message reject

Reject or deadletter a cloud-to-device message.

az iot device c2d-message send

Send a cloud-to-device message.

az iot device send-d2c-message

Send an mqtt device-to-cloud message. The command supports sending messages with application and system properties.

az iot device simulate

Simulate a device in an Azure IoT Hub.

While the device simulation is running, the device will automatically receive and acknowledge cloud-to-device (c2d) messages. For mqtt simulation, all c2d messages will be acknowledged with completion. For http simulation c2d acknowledgement is based on user selection which can be complete, reject or abandon.

Note: The command by default will set content-type to application/json and content-encoding to utf-8. This can be overriden.

az iot device upload-file

Upload a local file as a device to a pre-configured blob storage container.

az iot device send-d2c-message

Send an mqtt device-to-cloud message. The command supports sending messages with application and system properties.

az iot device send-d2c-message --device-id
                               [--da]
                               [--hub-name]
                               [--login]
                               [--mc]
                               [--properties]
                               [--qos {0, 1}]
                               [--resource-group]

Examples

Basic usage

az iot device send-d2c-message -n {iothub_name} -d {device_id}

Basic usage with custom data

az iot device send-d2c-message -n {iothub_name} -d {device_id} --data {message_body}

Send application properties

az iot device send-d2c-message -n {iothub_name} -d {device_id} --props 'key0=value0;key1=value1'

Send system properties (Message Id and Correlation Id)

az iot device send-d2c-message -n {iothub_name} -d {device_id} --props '$.mid=<id>;$.cid=<id>'

Required Parameters

--device-id -d

Target Device.

Optional Parameters

--da --data

Message body.

default value: Ping from Az CLI IoT Extension
--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--mc --msg-count

Number of device messages to send to IoT Hub.

default value: 1
--properties --props -p

Message property bag in key-value pairs with the following format: a=b;c=d. For mqtt messaging - you are able to send system properties using $.=value. For instance $.cid=12345 sets the system correlation Id property. Other system property identifier examples include $.ct for content type, $.mid for message Id and $.ce for content encoding.

--qos

Quality of Service. 0 = At most once, 1 = At least once. 2 (Exactly once) is not supported.

accepted values: 0, 1
default value: 1
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

az iot device simulate

Simulate a device in an Azure IoT Hub.

While the device simulation is running, the device will automatically receive and acknowledge cloud-to-device (c2d) messages. For mqtt simulation, all c2d messages will be acknowledged with completion. For http simulation c2d acknowledgement is based on user selection which can be complete, reject or abandon.

Note: The command by default will set content-type to application/json and content-encoding to utf-8. This can be overriden.

az iot device simulate --device-id
                       [--da]
                       [--hub-name]
                       [--login]
                       [--mc]
                       [--mi]
                       [--properties]
                       [--proto {http, mqtt}]
                       [--receive-settle {abandon, complete, reject}]
                       [--resource-group]

Examples

Basic usage (mqtt)

az iot device simulate -n {iothub_name} -d {device_id}

Basic usage (mqtt) with sending mixed properties

az iot device simulate -n {iothub_name} -d {device_id} --properties "myprop=myvalue;$.ct=application/json"

Basic usage (http)

az iot device simulate -n {iothub_name} -d {device_id} --protocol http

Basic usage (http) with sending mixed properties

az iot device simulate -n {iothub_name} -d {device_id} --protocol http --properties "iothub-app-myprop=myvalue;content-type=application/json;iothub-correlationid=12345"

Choose total message count and interval between messages

az iot device simulate -n {iothub_name} -d {device_id} --msg-count 1000 --msg-interval 5

Reject c2d messages (http only)

az iot device simulate -n {iothub_name} -d {device_id} --rs reject --protocol http

Abandon c2d messages (http only)

az iot device simulate -n {iothub_name} -d {device_id} --rs abandon --protocol http

Required Parameters

--device-id -d

Target Device.

Optional Parameters

--da --data

Message body.

default value: Ping from Az CLI IoT Extension
--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--mc --msg-count

Number of device messages to send to IoT Hub.

default value: 100
--mi --msg-interval

Delay in seconds between device-to-cloud messages.

default value: 3
--properties --props -p

Message property bag in key-value pairs with the following format: a=b;c=d. For mqtt messaging - you are able to send system properties using $.=value. For instance $.cid=12345 sets the system correlation Id property. Other system property identifier examples include $.ct for content type, $.mid for message Id and $.ce for content encoding. For http messaging - application properties are sent using iothub-app-=value, for instance iothub-app-myprop=myvalue. System properties are generally prefixed with iothub- like iothub-correlationid but there are exceptions such as content-type and content-encoding.

--proto --protocol

Indicates device-to-cloud message protocol.

accepted values: http, mqtt
default value: mqtt
--receive-settle --rs

Indicates how to settle received cloud-to-device messages. Supported with HTTP only.

accepted values: abandon, complete, reject
default value: complete
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

az iot device upload-file

Upload a local file as a device to a pre-configured blob storage container.

az iot device upload-file --content-type
                          --device-id
                          --file-path
                          [--hub-name]
                          [--login]
                          [--resource-group]

Required Parameters

--content-type --ct

MIME Type of file.

--device-id -d

Target Device.

--file-path --fp

Path to file for upload.

Optional Parameters

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.