0
votes

As a MQTT client (device), I am using devices/{deviceid}/messages/devicebound/# topic to receive Cloud to Device messages. This device is a gateway for me and there are 3 devices attached to it. I want to send 3 different commands to 1 gateway on 3 different topics, like

devices/{deviceid}/messages/devicebound/device1
devices/{deviceid}/messages/devicebound/device2
devices/{deviceid}/messages/devicebound/device3

My gateway is registered in iot-hub and I use it at {deviceid}.

Is it possible?

1

1 Answers

0
votes

Based on the official document "Communicate with your IoT hub using the MQTT protocol", it says:

Since IoT Hub is not a general purpose pub-sub messaging broker, it only supports the documented topic names and topic filters.

IoT Hub delivers messages with the Topic Name devices/{device_id}/messages/devicebound/, or devices/{device_id}/messages/devicebound/{property_bag} if there are any message properties.

Here is a solution using system property "messageId" as the filter. So your three topics:

devices/{deviceid}/messages/devicebound/device1 
devices/{deviceid}/messages/devicebound/device2 
devices/{deviceid}/messages/devicebound/device3

would look like this:

devices/{deviceid}/messages/devicebound/%24.mid=device1&%24.to=%2Fdevices%2Ftest1%2Fmessages%2FdeviceBound&iothub-ack=full
devices/{deviceid}/messages/devicebound/%24.mid=device2&%24.to=%2Fdevices%2Ftest1%2Fmessages%2FdeviceBound&iothub-ack=full
devices/{deviceid}/messages/devicebound/%24.mid=device3&%24.to=%2Fdevices%2Ftest1%2Fmessages%2FdeviceBound&iothub-ack=full

This is the test:

Send C2D message from azure device explorer:

enter image description here

Receive C2D message from MQTTBox:

enter image description here