How to represent C2D message in IoT Plug & Play DTDL definition

87 views Asked by At

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,

1

There are 1 answers

3
SaiSakethGuduru On

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.

  1. 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);
             }
         }

  1. Add ReceiveC2dAsync() in main method before console.ReadLine().