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.
az iot device simulate Simulate a device in an Azure IoT Hub.
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.

az iot device send-d2c-message --device-id
[--da]
[--hub-name]
[--login]
[--mc]
[--properties]
[--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.

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

az iot device simulate --device-id
[--da]
[--hub-name]
[--login]
[--mc]
[--mi]
[--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 (http).

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

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}

Abandon c2d messages (http only)

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

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