Source: Azure CLI Cheatsheet
Requirements
az extension add --name azure-iot # install IoT extension
az --version # verify both CLI and extensionKey Commands
Setup (environment variables)
export IOT_DEVICE_NAME=simDevice
export IOTHUB_NAME=YourIoTHubNameCreate a Device
az iot hub device-identity create -d ${IOT_DEVICE_NAME} -n ${IOTHUB_NAME}Simulate a Device (sends D2C messages)
az iot device simulate -d ${IOT_DEVICE_NAME} -n ${IOTHUB_NAME}
# Default payload: "Ping from Az CLI IoT Extension"
# Ctrl+C to stopMonitor Events (all D2C messages)
az iot hub monitor-events --output table -p all -n ${IOTHUB_NAME}
az iot hub monitor-events --output table --device-id ${IOT_DEVICE_NAME} --hub-name ${IOTHUB_NAME}If uamqp errors: pip install uamqp
Send C2D Message
az iot device c2d-message send -d ${IOT_DEVICE_NAME} --data "Hello World" --props "key0=value0;key1=value1" -n ${IOTHUB_NAME}Invoke Direct Method on Device
az iot hub invoke-device-method --mn ${METHOD_NAME} -d ${IOT_DEVICE_NAME} -n ${IOTHUB_NAME}Update Device Twin (desired properties)
az iot hub device-twin update -d ${IOT_DEVICE_NAME} --desired '{"conditions":{"temperature":{"warning":98}}}' -n ${IOTHUB_NAME}Get Device Twin (reported properties)
az iot hub device-twin show -d ${IOT_DEVICE_NAME} --query properties.reported -n ${IOTHUB_NAME}Connection Strings
Device connection string (for device SDK)
az iot hub device-identity connection-string show \
--device-id ${IOT_DEVICE_NAME} \
--hub-name ${IOTHUB_NAME}Service connection string (for back-end apps)
az iot hub connection-string show \
--policy-name service \
--hub-name ${IOTHUB_NAME}EventHub-compatible connection string
az iot hub connection-string show -n ${IOTHUB_NAME} --default-eventhubSee Also
- Azure IoT Overview topic
- Device Twins source