Skip to content

Commit 5e11269

Browse files
committed
added links to protocol table and a couple of examples
1 parent 6d6b255 commit 5e11269

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

articles/iot-hub/iot-hub-mqtt-support.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A device can use the MQTT protocol to connect to an IoT hub using any of the fol
2828
* Libraries in the [Azure IoT SDKs](https://github.com/Azure/azure-iot-sdks).
2929
* The MQTT protocol directly.
3030

31-
The MQTT port (8883) is blocked in many corporate and educational networking environments. If you can't open port 8883 in your firewall, we recommend using MQTT over Web Sockets. MQTT over Web Sockets communicates over port 443, which is almost always open in networking environments. To learn how to specify the MQTT protocol when using the Azure IoT SDKs, see [Using the device SDKs](#using-the-device-sdks).
31+
The MQTT port (8883) is blocked in many corporate and educational networking environments. If you can't open port 8883 in your firewall, we recommend using MQTT over Web Sockets. MQTT over Web Sockets communicates over port 443, which is almost always open in networking environments. To learn how to specify the MQTT and MQTT over Web Sockets protocols when using the Azure IoT SDKs, see [Using the device SDKs](#using-the-device-sdks).
3232

3333
## Using the device SDKs
3434

@@ -41,11 +41,26 @@ The following table contains links to code samples for each supported language a
4141
| Language | MQTT protocol parameter | MQTT over Web Sockets protocol parameter
4242
| --- | --- | --- |
4343
| [Node.js](https://github.com/Azure/azure-iot-sdk-node/blob/master/device/samples/simple_sample_device.js) | azure-iot-device-mqtt.Mqtt | azure-iot-device-mqtt.MqttWs |
44-
| [Java](https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/send-receive-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/SendReceive.java) |IotHubClientProtocol.MQTT | IotHubClientProtocol.MQTT_WS |
45-
| [C](https://github.com/Azure/azure-iot-sdk-c/tree/master/iothub_client/samples/iothub_client_sample_mqtt_dm) | MQTT_Protocol | MQTT_WebSocket_Protocol |
46-
| [C#](https://github.com/Azure/azure-iot-sdk-csharp/tree/master/iothub/device/samples) | TransportType.Mqtt | TransportType.Mqtt falls back to MQTT over Web Sockets if MQTT fails. To specify MQTT over Web Sockets only, use TransportType.Mqtt_WebSocket_Only |
44+
| [Java](https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/send-receive-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/SendReceive.java) |[IotHubClientProtocol](https://docs.microsoft.com/java/api/com.microsoft.azure.sdk.iot.device.iothubclientprotocol?view=azure-java-stable).MQTT | IotHubClientProtocol.MQTT_WS |
45+
| [C](https://github.com/Azure/azure-iot-sdk-c/tree/master/iothub_client/samples/iothub_client_sample_mqtt_dm) | [MQTT_Protocol](https://docs.microsoft.com/azure/iot-hub/iot-c-sdk-ref/iothubtransportmqtt-h/mqtt-protocol) | [MQTT_WebSocket_Protocol](https://docs.microsoft.com/azure/iot-hub/iot-c-sdk-ref/iothubtransportmqtt-websockets-h/mqtt-websocket-protocol) |
46+
| [C#](https://github.com/Azure/azure-iot-sdk-csharp/tree/master/iothub/device/samples) | [TransportType](https://docs.microsoft.com/dotnet/api/microsoft.azure.devices.client.transporttype?view=azure-dotnet).Mqtt | TransportType.Mqtt falls back to MQTT over Web Sockets if MQTT fails. To specify MQTT over Web Sockets only, use TransportType.Mqtt_WebSocket_Only |
4747
| [Python](https://github.com/Azure/azure-iot-sdk-python/tree/master/azure-iot-device/samples) | Supports MQTT by default | Add `websockets=True` in the call to create the client |
4848

49+
The following fragment shows how to specify the MQTT over Web Sockets protocol when using the Azure IoT Node.js SDK:
50+
51+
```javascript
52+
var Client = require('azure-iot-device').Client;
53+
var Protocol = require('azure-iot-device-mqtt').MqttWs;
54+
var client = Client.fromConnectionString(deviceConnectionString, Protocol);
55+
```
56+
57+
The following fragment shows how to specify the MQTT over Web Sockets protocol when using the Azure IoT Python SDK:
58+
59+
```python
60+
from azure.iot.device.aio import IoTHubDeviceClient
61+
device_client = IoTHubDeviceClient.create_from_connection_string(deviceConnectionString, websockets=True)
62+
```
63+
4964
### Default keep-alive timeout
5065

5166
In order to ensure a client/IoT Hub connection stays alive, both the service and the client regularly send a *keep-alive* ping to each other. The client using IoT SDK sends a keep-alive at the interval defined in this table below:

0 commit comments

Comments
 (0)