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)

MethodUse case
D2C messagesTime-series telemetry, alerts
File uploadsLarge data, intermittent connectivity
Device twin reported propertiesReport device state/config

Cloud to Device (C2D)

MethodUse case
C2D messagesOne-way notifications to device
Direct methodsRequest-response, immediate result (e.g., turn on fan)
Twin desired propertiesLong-running config changes

Device Twins

JSON documents per device. NOT for telemetry — use D2C messages for that.

PropertySet byRead by
tagsBack-endBack-end
desiredBack-endDevice
reportedDeviceBack-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 $HUB

Python SDK Packages

pip install azure-iot-device    # device-side
pip install azure-iot-hub       # service/back-end
pip install azure-mgmt-iothub   # hub management

See Also