You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot/iot-mqtt-connect-to-iot-hub.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -295,7 +295,7 @@ The following list summarizes IoT Hub MQTT implementation-specific behaviors:
295
295
296
296
For more information, see [Send device-to-cloud and cloud-to-device messages with IoT Hub](../iot-hub/iot-hub-devguide-messaging.md).
297
297
298
-
## Receiving cloud-to-device messages
298
+
## Receive cloud-to-device messages
299
299
300
300
To receive messages from IoT Hub, a device should subscribe using `devices/{device-id}/messages/devicebound/#` as a **Topic Filter**. The multi-level wildcard `#` in the topic filter is used to enable the device to receive more properties in the topic name. IoT Hub doesn't allow the usage of the `#` or `?` wildcards to filter subtopics. IoT Hub isn't a general-purpose publish-subscribe messaging broker, it only supports the documented topic names and topic filters. A device can only subscribe to five topics at a time.
# Tutorial - Use MQTT to develop an IoT device client without using a device SDK
15
14
16
-
You should use one of the Azure IoT Device SDKs to build your IoT device clients if at all possible. However, in scenarios such as using a memory constrained device, you may need to use an MQTT library to communicate with your IoT hub.
15
+
You should use one of the Azure IoT Device SDKs to build your IoT device clients if at all possible. However, in scenarios such as using a memory constrained device, you might need to use an MQTT library to communicate with your IoT hub.
17
16
18
17
The samples in this tutorial use the [Eclipse Mosquitto](http://mosquitto.org/) MQTT library.
19
18
20
19
In this tutorial, you learn how to:
21
20
22
-
> [!div class="checklist"]
23
-
> * Build the C language device client sample applications.
24
-
> * Run a sample that uses the MQTT library to send telemetry.
25
-
> * Run a sample that uses the MQTT library to process a cloud-to-device message sent from your IoT hub.
26
-
> * Run a sample that uses the MQTT library to manage the device twin on the device.
21
+
* Build the C language device client sample applications.
22
+
* Run a sample that uses the MQTT library to send telemetry.
23
+
* Run a sample that uses the MQTT library to process a cloud-to-device message sent from your IoT hub.
24
+
* Run a sample that uses the MQTT library to manage the device twin on the device.
27
25
28
26
You can use either a Windows or Linux development machine to complete the steps in this tutorial.
29
27
30
28
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
1. Install [Visual Studio (Community, Professional, or Enterprise)](https://visualstudio.microsoft.com/downloads). Be sure to enable the **Desktop development with C++** workload.
41
37
42
38
1. Install [CMake](https://cmake.org/download/). Enable the **Add CMake to the system PATH for all users** option.
43
39
44
40
1. Install the **x64 version** of [Mosquitto](https://mosquitto.org/download/).
45
41
46
-
If you're using Linux:
42
+
# [Linux](#tab/linux)
47
43
48
44
1. Run the following command to install the build tools:
If you don't already have an IoT hub, run the following commands to create a free-tier IoT hub in a resource group called `mqtt-sample-rg`. The command uses the name `my-hub` as an example for the name of the IoT hub to create. Choose a unique name for your IoT hub to use in place of `my-hub`:
@@ -85,6 +85,8 @@ Make a note of the SAS token the command outputs as you need it later. The SAS t
85
85
> [!TIP]
86
86
> By default, the SAS token is valid for 60 minutes. The `--du 7200` option in the previous command extends the token duration to two hours. If it expires before you're ready to use it, generate a new one. You can also create a token with a longer duration. To learn more, see [az iot hub generate-sas-token](/cli/azure/iot/hub#az-iot-hub-generate-sas-token).
Use the following command to clone the sample repository to a suitable location on your local machine:
@@ -148,7 +150,7 @@ Run the _mosquitto_telemetry_ sample. For example, on Linux:
148
150
149
151
The `az iot hub monitor-events` generates the following output that shows the payload sent by the device:
150
152
151
-
```text
153
+
```output
152
154
Starting event monitor, use ctrl-c to stop...
153
155
{
154
156
"event": {
@@ -199,11 +201,11 @@ if (rc != MOSQ_ERR_SUCCESS)
199
201
printf("Publish returned OK\r\n");
200
202
```
201
203
202
-
To learn more, see [Sending device-to-cloud messages](./iot-mqtt-connect-to-iot-hub.md#sending-device-to-cloud-messages).
204
+
To learn more, see [Sending device-to-cloud messages](./iot-mqtt-connect-to-iot-hub.md#send-device-to-cloud-messages).
203
205
204
206
## Receive a cloud-to-device message
205
207
206
-
The *mosquitto_subscribe* sample shows how to subscribe to MQTT topics and receive a cloud-to-device message from your IoT hub by using the MQTT library.
208
+
The _mosquitto_subscribe_ sample shows how to subscribe to MQTT topics and receive a cloud-to-device message from your IoT hub by using the MQTT library.
207
209
208
210
Run the _mosquitto_subscribe_ sample. For example, on Linux:
To learn more, see [Use MQTT to update a device twin reported property](./iot-mqtt-connect-to-iot-hub.md#update-device-twins-reported-properties) and [Use MQTT to retrieve a device twin property](./iot-mqtt-connect-to-iot-hub.md#retrieving-a-device-twins-properties).
353
+
To learn more, see [Use MQTT to update a device twin reported property](./iot-mqtt-connect-to-iot-hub.md#update-device-twins-reported-properties) and [Use MQTT to retrieve a device twin property](./iot-mqtt-connect-to-iot-hub.md#retrieve-device-twin-properties).
Now that you've learned how to use the Mosquitto MQTT library to communicate with IoT Hub, a suggested next step is to review the [MQTT Application samples](https://github.com/Azure-Samples/MqttApplicationSamples) on GitHub.
0 commit comments