Azure IoT Overview
IoT Hub
Central broker for device communication. Free tier: 8,000 messages/day.
Protocols: MQTT (default for Python SDK), AMQP, HTTPS.
D2C vs C2D Options
Device to Cloud (D2C)
| Method | Use case |
|---|---|
| D2C messages | Time-series telemetry, alerts |
| File uploads | Large data, intermittent connectivity |
| Device twin reported properties | Report device state/config |
Cloud to Device (C2D)
| Method | Use case |
|---|---|
| C2D messages | One-way notifications to device |
| Direct methods | Request-response, immediate result (e.g., turn on fan) |
| Twin desired properties | Long-running config changes |
Device Twins
JSON documents per device. NOT for telemetry — use D2C messages for that.
| Property | Set by | Read by |
|---|---|---|
tags | Back-end | Back-end |
desired | Back-end | Device |
reported | Device | Back-end |
Flow: back-end sets desired → device reads → device acts → device sets reported → back-end reads reported.
from azure.iot.hub import IoTHubDeviceClient
device_client = IoTHubDeviceClient.create_from_connection_string(conn_str)
device_client.connect()
twin = device_client.get_twin() # read full twin
reported_patch = {"telemetry_interval": 20}
device_client.patch_twin_reported_properties(reported_patch) # update reported
device_client.shutdown()Event Hubs
IoT Hub D2C endpoints = Event Hub endpoints. Use EventHub SDK to read D2C messages.
Structure: partitions (free tier = 2) → offset per event → checkpoint to resume.
Blob Storage
Storage Account → Container → Blob (file)
For IoT: use Azure Data Lake Storage Gen2 (hierarchical dirs for telemetry organization).
Azure CLI Quick Reference
# Setup
az extension add --name azure-iot
# Device management
az iot hub device-identity create -d $DEVICE -n $HUB
az iot device simulate -d $DEVICE -n $HUB
az iot hub monitor-events --output table -n $HUB
# Twin operations
az iot hub device-twin update -d $DEVICE --desired '{"key": "value"}' -n $HUB
az iot hub device-twin show -d $DEVICE --query properties.reported -n $HUB
# C2D
az iot device c2d-message send -d $DEVICE --data "msg" -n $HUB
az iot hub invoke-device-method --mn $METHOD -d $DEVICE -n $HUB
# Connection strings
az iot hub device-identity connection-string show --device-id $DEVICE --hub-name $HUB
az iot hub connection-string show --policy-name service --hub-name $HUBPython SDK Packages
pip install azure-iot-device # device-side
pip install azure-iot-hub # service/back-end
pip install azure-mgmt-iothub # hub managementSee Also
- IoT System Architecture topic
- MQTT and IoT Protocols topic
- device-to-cloud-communication source, device-twins source