Skip to content

Commit a4b3e59

Browse files
Make default QoS Level to AtLeastOnce to match default Azure device SDK behavior (#74)
Co-authored-by: Beaugrand, Kevin <[email protected]> Co-authored-by: Laurent Ellerbach <[email protected]>
1 parent e612f82 commit a4b3e59

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ void StatusUpdatedEvent(object sender, StatusUpdatedEventArgs e)
302302

303303
Note that those are status change based, so once the connect or disconnect event arrives, they'll be replaced by other events as soon as something else happened like receiving a twin.
304304

305+
### QoS Level
306+
307+
By default, the device SDKs connect to an IoT Hub use QoS 1 for message exchange with the IoT hub. You can change this by setting the `qosLevel` argument of the `DeviceClient` constructor.
308+
309+
Here are existing QoS levels that you can use:
310+
311+
* AtMostOnce: The broker/client will deliver the message once, with no confirmation.
312+
* AtLeastOnce: The broker/client will deliver the message at least once, with confirmation required.
313+
* ExactlyOnce: The broker/client will deliver the message exactly once by using a four step handshake.
314+
315+
While it's possible to configure QoS 0 (AtMostOnce) for faster message exchange, you should note that the delivery isn't guaranteed nor acknowledged. For this reason, QoS 0 is often referred as "fire and forget".
316+
305317
## Azure IoT Device Provisioning Service (DPS) support
306318

307319
This SDK also supports the Azure IoT Device Provisioning Service. Group and individual provisioning scenarios are supported either with a symmetric key either with certificates. To understand the mechanism behind DPS, it is recommended to read the [documentation](https://docs.microsoft.com/azure/iot-dps/).
@@ -336,7 +348,7 @@ if(myDevice.Status != ProvisioningRegistrationStatusType.Assigned)
336348
}
337349

338350
// You can then create the device
339-
var device = new DeviceClient(myDevice.AssignedHub, myDevice.DeviceId, SasKey, nanoFramework.M2Mqtt.Messages.MqttQoSLevel.AtMostOnce, azureCA);
351+
var device = new DeviceClient(myDevice.AssignedHub, myDevice.DeviceId, SasKey, nanoFramework.M2Mqtt.Messages.MqttQoSLevel.AtLeastOnce, azureCA);
340352
// Open it and continue like for the previous sections
341353
var res = device.Open();
342354
if(!res)
@@ -395,7 +407,7 @@ if(myDevice.Status != ProvisioningRegistrationStatusType.Assigned)
395407
}
396408

397409
// You can then create the device
398-
var device = new DeviceClient(myDevice.AssignedHub, myDevice.DeviceId, deviceCert, nanoFramework.M2Mqtt.Messages.MqttQoSLevel.AtMostOnce, azureCA);
410+
var device = new DeviceClient(myDevice.AssignedHub, myDevice.DeviceId, deviceCert, nanoFramework.M2Mqtt.Messages.MqttQoSLevel.AtLeastOnce, azureCA);
399411
// Open it and continue like for the previous sections
400412
var res = device.Open();
401413
if(!res)

nanoFramework.Azure.Devices.Client/DeviceClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class DeviceClient : IDisposable
6565
/// <param name="qosLevel">The default quality level delivery for the MQTT messages, default to the lower quality</param>
6666
/// <param name="azureCert">Azure certificate for the connection to Azure IoT Hub</param>
6767
/// <param name="modelId">Azure Plug and Play model ID</param>
68-
public DeviceClient(string iotHubName, string deviceId, string sasKey, MqttQoSLevel qosLevel = MqttQoSLevel.AtMostOnce, X509Certificate azureCert = null, string modelId = null)
68+
public DeviceClient(string iotHubName, string deviceId, string sasKey, MqttQoSLevel qosLevel = MqttQoSLevel.AtLeastOnce, X509Certificate azureCert = null, string modelId = null)
6969
{
7070
_isCertificate = false;
7171
_clientCert = null;

0 commit comments

Comments
 (0)