Azure IoT Hub never receives the message

Chris Rickard 6 Reputation points
2022-07-08T03:50:15.04+00:00

This tutorial code a simulated IoT device app that sends device-to-cloud messages using Azure IoT Hub. This app works as advertised. I am able to see the telemetry data in Azure.

This companion tutorial builds an app to send messages to the simulated IoT device app in the first tutorial (presumably) over MQTT. The first thing they have you do to enable this is add the following code:

var client = DeviceClient.fromConnectionString(connectionString, Mqtt);  
  
client.on('message', function (msg) {  
  console.log('Id: ' + msg.messageId + ' Body: ' + msg.data);  
  client.complete(msg, function (err) {  
    if (err) {  
      console.error('complete error: ' + err.toString());  
    } else {  
      console.log('complete sent');  
    }  
  });  
});  

Note the specification of Mqtt parameter in the fromConnectionString call. The second app uses ServiceClient.SendAsync to send the message. It uses the following code to send a message:

private async static Task SendCloudToDeviceMessageAsync()  
{  
     var commandMessage = new  
      Message(Encoding.ASCII.GetBytes("Cloud to device message."));  
     await serviceClient.SendAsync(targetDevice, commandMessage);  
}  

As is, the simulated IoT device never receives the message from the C# app. The ServiceClient.SendAsync Method documents that it is sent over AMQP. As noted, the first app clearly uses Mqtt.

I question whether the AMQP protocol is the issue. Can anyone point me in the right direction to troubleshoot where the message goes and why the app never receives it?

Azure IoT Hub
Azure IoT Hub

An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.


1 answer

Sort by: Oldest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.