Device direct methods
Azure IoT Hub provides fully managed bidirectional communication between the IoT solution on the backend and the IoT devices in the fields. We will be considering detailed message communication in Chapter 3, IoT Hub Messaging and Commands.
When there is a need for an immediate communication result, a direct method best suits these scenarios. Let's take an example of a home automation system. One needs to control the AC temperature or turn the faucet showers on/off. It uses the HTTP protocol for method invocation.
How to do it...
The following steps will be taken to perform a direct method with an IoT device connected with IoT Hub:
- Invoke this method from the application:
public async Task<CloudToDeviceMethodResult> InvokeDirectMethodOnDevice(string deviceId, ServiceClient serviceClient) { var methodInvocation = new CloudToDeviceMethod("WriteToMessage") { ResponseTimeout = TimeSpan.FromSeconds(300) }; methodInvocation.SetPayloadJson("'1234567890'"); var response...