Messaging - commands and control
Any IoT device which is capable of receiving messages from the cloud makes a bidirectional command execution easy. The device can receive the message and process upon the instruction on the hardware side. Once the action is taken, an acknowledgement is sent to the cloud about the action completion. With the IoT Hub SDK for the device and the backend application, we can achieve this. We must follow the following steps:
How to do it...
In this section we will send a cloud-to-device message. Upon receiving it, the IoT device will perform an action:
- Send a cloud-to-device message from a cloud solution to an IoT device:
ServiceClient serviceClient; serviceClient = ServiceClient.CreateFromConnectionString(abc.GetConnectionString()); abc.SendCloudToDeviceMessageAsync(deviceId, serviceClient);
- Prepare and send messages:
var commandMessage = new Message(Encoding.ASCII.GetBytes("Close=100")); await serviceClient.SendAsync(deviceId, commandMessage);
- The IoT device will reply...