Source: Device to Cloud Communication (Azure)
Azure IoT Protocols
Azure IoT Hub supports:
- MQTT (including over WebSockets) — used by Python SDK by default
- AMQP (including over WebSockets) — more overhead than MQTT, no broker required, extra security/flow control features
- HTTPS
D2C — Device to Cloud Options
| Method | Use case |
|---|---|
| Device-to-cloud messages | Time series telemetry, alerts |
| File uploads | Media, large telemetry batches (intermittently connected) |
| Device twin reported properties | Report device state / last known config |
C2D — Cloud to Device Options
| Method | Use case |
|---|---|
| Cloud-to-device messages | One-way notifications to device |
| Direct methods | Request-response, immediate confirmation (e.g., turn on fan) |
| Twin desired properties | Long-running commands to put device in a desired state |
Message Anatomy
An IoT Hub message has 3 parts:
{
"message": {
"systemProperties": {
"contentType": "application/json",
"contentEncoding": "UTF-8",
"iothub-message-source": "deviceMessages",
"iothub-enqueuedtime": "2017-05-08T18:55:31.8514657Z"
},
"appProperties": {
"processingPath": "{cold | warm | hot}",
"verbose": "{true, false}",
"severity": "1-5",
"testDevice": "{true | false}"
},
"body": "{\"Weather\":{\"Temperature\":50}}"
}
}- systemProperties: auto-set, identify content type/encoding
- appProperties: custom key-value pairs (ASCII alphanumeric only)
- body: opaque binary payload (typically JSON)
Send via Python: IoTHubDeviceClient.send_message(message) — can pass string or Message object.
Direct Methods Lifecycle
- Service/back-end app sends Direct Method request to device (via SDK or
az iot hub invoke-device-method) - Device receives method, processes it, prepares response
- Response sent back to sender
- App handles response via callback
Python device side uses IotHubDeviceClient from azure.iot.device.aio.
Endpoints
IoT Hub = broker; endpoints = topics. Messages retained up to 7 days (1 day default).
See Also
- Azure IoT Overview topic
- MQTT and IoT Protocols topic