简体   繁体   中英

Azure IoT Hub : Cloud to Device messaging using MQTT and SDK

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM