'How to represent C2D message in IoT Plug & Play DTDL definition
I'd like to know how to represent C2D message and External message on IoT Edge module by IoT Plug & Play DTDL definition. I thought that a Command with a value of "asynchronous" in commandType property is used as C2D message. But when I check the behavior in IoT Central, such a command is handled as a direct method invocation. Is it possible to represent C2D message by IoT PnP model? If yes, please let me know how to describe that. regards,
Solution 1:[1]
It is a fully managed service which enable secure bidirectional communication between large no of devices and back end.
Simulated Device
: connects to your IoThub and receive cloud-to-device messages.SendCloudToDevice
: app Sends a cloud to device message to device app with the help of IOT hub.
To receive cloud-to-device messages from the IoT hub.
- Inside visual studio, in the Simulated Device project add given method to Simulated Device class.
private static async void ReceiveC2dAsync()
{
Console.WriteLine("\nReceiving cloud to device messages from service");
while (true)
{
Message receivedMessage = await s_deviceClient.ReceiveAsync();
if (receivedMessage == null) continue;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Received message: {0}",
Encoding.ASCII.GetString(receivedMessage.GetBytes()));
Console.ResetColor();
await s_deviceClient.CompleteAsync(receivedMessage);
}
}
- Add
ReceiveC2dAsync()
in main method beforeconsole.ReadLine()
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SaiSakethGuduru-MT |