Skip to content

Commit cec2c9a

Browse files
committed
Add topic filter
1 parent c26676f commit cec2c9a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

articles/iot-develop/tutorial-use-mqtt.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ If you don't have an Azure subscription, create a [free account](https://azure.m
3434

3535
[!INCLUDE [azure-cli-prepare-your-environment-h3](~/articles/reusable-content/azure-cli/azure-cli-prepare-your-environment-h3.md)]
3636

37+
### Development machine prerequisites
38+
3739
If you're using Windows:
3840

3941
1. Install [Visual Studio (Community, Professional, or Enterprise)](https://visualstudio.microsoft.com/downloads). Be sure to enable the **Desktop development with C++** workload.
@@ -228,13 +230,13 @@ Got message for devices/mqtt-dev-01/messages/# topic
228230
229231
The following snippets are taken from the _mosquitto/src/mosquitto_subscribe.cpp_ file.
230232
231-
The following statement defines the topic the device uses to receive cloud to device messages:
233+
The following statement defines the topic filter the device uses to receive cloud to device messages. The `#` is a multi-level wildcard:
232234
233235
```c
234236
#define DEVICEMESSAGE "devices/" DEVICEID "/messages/#"
235237
```
236238
237-
The `main` function uses the `mosquitto_message_callback_set` function to set a callback to handle messages sent from your IoT hub and uses the `mosquitto_subscribe` function to subscribe to the `#` topic. The following snippet shows the callback function:
239+
The `main` function uses the `mosquitto_message_callback_set` function to set a callback to handle messages sent from your IoT hub and uses the `mosquitto_subscribe` function to subscribe to all messages. The following snippet shows the callback function:
238240
239241
```c
240242
void message_callback(struct mosquitto* mosq, void* obj, const struct mosquitto_message* message)
@@ -309,7 +311,7 @@ void connect_callback(struct mosquitto* mosq, void* obj, int result)
309311
}
310312
```
311313
312-
The device subscribes to the `$iothub/twin/res/#` topic and when it receives a message from your IoT hub, the `message_callback` function handles it. When you run the sample, the `message_callback` function gets called twice. The first time, the device receives a response from the IoT hub to the reported property update and then requests the device twin. The second time, the device receives the requested device twin. The following snippet shows the `message_callback` function:
314+
The device subscribes to the `$iothub/twin/res/#` topic and when it receives a message from your IoT hub, the `message_callback` function handles it. When you run the sample, the `message_callback` function gets called twice. The first time, the device receives a response from the IoT hub to the reported property update. The device then requests the device twin. The second time, the device receives the requested device twin. The following snippet shows the `message_callback` function:
313315
314316
```c
315317
void message_callback(struct mosquitto* mosq, void* obj, const struct mosquitto_message* message)

0 commit comments

Comments
 (0)