IoT Hub provides three options for device apps to expose functionality to a back-end app:
Direct methods for communications that require immediate confirmation of the result. Direct methods are often used for interactive control of devices such as turning on a fan.
Twin's desired properties for long-running commands intended to put the device into a certain desired state. For example, set the telemetry send interval to 30 minutes.
Here is a detailed comparison of the various cloud-to-device communication options.
Categories
Direct methods
Twin's desired properties
Cloud-to-device messages
Scenario
Commands that require immediate confirmation, such as turning on a fan.
Long-running commands intended to put the device into a certain desired state. For example, set the telemetry send interval to 30 minutes.
One-way notifications to the device app.
Data flow
Two-way. The device app can respond to the method right away. The solution back end receives the outcome contextually to the request.
One-way. The device app receives a notification with the property change.
One-way. The device app receives the message
Durability
Disconnected devices are not contacted. The solution back end is notified that the device is not connected.
Property values are preserved in the device twin. Device will read it at next reconnection. Property values are retrievable with the IoT Hub query language.
Messages can be retained by IoT Hub for up to 48 hours.
Targets
Single device using deviceId, or multiple devices using jobs.
Single device using deviceId, or multiple devices using jobs.
Single device by deviceId.
Size
Maximum direct method payload size is 128 KB for the request and 128 KB for the response.
This article describes device-to-cloud and cloud-to-device messaging with IoT Hub, with information about message formats and supported communications protocols.
This developer guide discusses how to use cloud-to-device messaging with your IoT hub. It includes information about the message life cycle and configuration options.
This article describes scheduling jobs to run on multiple devices connected to your IoT hub. Jobs can update tags and desired properties and invoke direct methods on multiple devices.
The Azure IoT Hub conceptual documentation includes discussions of endpoints, security, the identity registry, device management, direct methods, device twins, file uploads, jobs, the IoT Hub query language, messaging, and many other features.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.