Hi,
I am Working on IoT technology, in one of my project I want scenario like receiving the messages from cloud(IoT hub) to devices, so for that concept I have wrote below lines of code but it will always give null value.
private static async void ReceiveC2dAsync()
{
Debug.WriteLine("\nReceiving cloud to device messages from service");
while (true)
{
Message receivedMessage = await deviceClient.ReceiveAsync();
if (receivedMessage == null)
continue;
{
Debug.WriteLine("\nReceiving cloud to device messages from service");
while (true)
{
Message receivedMessage = await deviceClient.ReceiveAsync();
if (receivedMessage == null)
continue;
//Console.ForegroundColor = ConsoleColor.Yellow;
Debug.WriteLine("Received message: {0}", Encoding.ASCII.GetString(receivedMessage.GetBytes()));
//Debug.ResetColor();
Debug.WriteLine("Received message: {0}", Encoding.ASCII.GetString(receivedMessage.GetBytes()));
//Debug.ResetColor();
await deviceClient.CompleteAsync(receivedMessage);
}
}
}
}
in the above code i was always getting receivedMessage as null.
Please tell me how to resolve this issue.
Regards,
Pradeep