1
votes

Microsoft has its own SDK for interacting with IoT Hub (Microsoft.Azure.Devices) It features a client called ServiceClient that as I understand it is client you are supposed to use when sending messages from your backend to a device through IoT hub.

When initializing the ServiceClient like below the only supported TransportTypes are Amqp and Amqp_websockets_only. My devices only support MQTT. How should I go about that?

public async Task SendMessage() { var serviceClient = ServiceClient.CreateFromConnectionString("", TransportType.Amqp); var commandMessage = new Message(Encoding.ASCII.GetBytes("Cloud to device message.")); await serviceClient.SendAsync("myFirstDevice", commandMessage); }

According to the c2d guidelines "all protocols" are supported.

I have read through this documentation, but it only documents device to cloud, not cloud to device.

Looking at the SDK documentation it only lists AMQP for key features under device-to-cloud

1
Are you sure this feature is related to the device-to-cloud messaging?Roman Kiss
I am not sure about anything. This is new territory for me.WPFUser
OK, the table in this document shows a Cloud-to-device messaging and protocol AMQP and AMQP-WS for your backend app. That's correct. The backend communicated to the devices via the Azure IoT Hub (service-facing endpoint) and using only AMQP and AMQP-WS protocols, but the Azure IoT Hub communicated with a device (device-facing endpoint) via a connected device protocol such as MQTT, AMQP or Https.Roman Kiss

1 Answers

4
votes

For device-to-cloud messaging, the device can use the MQTT, MQTT-WS, AMQP, AMQP-WS, or HTTP protocols. See the IoT Hub device SDK key features. A device communicates with IoT Hub for both d2c and c2d using the Microsoft Azure IoT device SDK for .NET. Note that there are also device SDKs available for Java, Node, Python and C.

If you have a back-end application that needs to send a c2d message to a device, then that back-end application should use one of the Azure IoT service SDKs such as Microsoft Azure IoT service SDK for C# to connect to IoT Hub and send the c2d message. The back-end application must use AMQP or AMQP-WS.

The protocol used by the device to connect to IoT Hub is independent of the protocol used by the back-end application to connect to IoT Hub. For example, a back-end application could connect to IoT Hub using AMQP to send a c2d message to a device that's connected to the hub using MQTT.