Class DeviceClient
- Namespace
- nanoFramework.Azure.Devices.Client
- Assembly
- nanoFramework.Azure.Devices.Client.dll
Azure IoT Client SDK for .NET nanoFramework using MQTT.
public class DeviceClient : IDisposable
- Inheritance
-
DeviceClient
- Implements
- Inherited Members
- Extension Methods
Constructors
DeviceClient(string, string, byte[], MqttQoSLevel, byte[], string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, byte[] clientCert = null, MqttQoSLevel qosLevel = MqttQoSLevel.AtMostOnce, byte[] azureCert = null, string modelId = null)
Parameters
iotHubNamestringYour Azure IoT Hub fully qualified domain name (example: youriothub.azure-devices.net).
deviceIdstringThe device ID (name of your device).
clientCertbyte[]The certificate to connect the device (containing both public and private keys). Pass null if you are using the certificate store on the device.
qosLevelMqttQoSLevelThe default quality of assurance level for delivery for the MQTT messages (defaults to the lowest quality).
azureCertbyte[]Azure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(string, string, X509Certificate2, MqttQoSLevel, X509Certificate, string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, X509Certificate2 clientCert, MqttQoSLevel qosLevel = MqttQoSLevel.AtMostOnce, X509Certificate azureCert = null, string modelId = null)
Parameters
iotHubNamestringYour Azure IoT Hub fully qualified domain name (example: youriothub.azure-devices.net).
deviceIdstringThe device ID (name of your device).
clientCertX509Certificate2The certificate to connect the device (containing both public and private keys). Pass null if you are using the certificate store on the device.
qosLevelMqttQoSLevelThe default quality of assurance level for delivery for the MQTT messages (defaults to the lowest quality).
azureCertX509CertificateAzure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(string, string, string, byte[], MqttQoSLevel, byte[], string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, string moduleId, byte[] clientCert = null, MqttQoSLevel qosLevel = MqttQoSLevel.AtMostOnce, byte[] azureCert = null, string modelId = null)
Parameters
iotHubNamestringYour Azure IoT Hub fully qualified domain name (example: youriothub.azure-devices.net).
deviceIdstringThe device ID (name of your device).
moduleIdstringThe module ID which is attached to the device ID.
clientCertbyte[]The certificate to connect the device (containing both public and private keys). Pass null if you are using the certificate store on the device.
qosLevelMqttQoSLevelThe default quality of assurance level for delivery for the MQTT messages (defaults to the lowest quality).
azureCertbyte[]Azure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(string, string, string, X509Certificate2, MqttQoSLevel, X509Certificate, string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, string moduleId, X509Certificate2 clientCert, MqttQoSLevel qosLevel = MqttQoSLevel.AtMostOnce, X509Certificate azureCert = null, string modelId = null)
Parameters
iotHubNamestringYour Azure IoT Hub fully qualified domain name (example: youriothub.azure-devices.net).
deviceIdstringThe device ID (name of your device).
moduleIdstringThe module ID which is attached to the device ID.
clientCertX509Certificate2The certificate to connect the device (containing both public and private keys). Pass null if you are using the certificate store on the device.
qosLevelMqttQoSLevelThe default quality of assurance level for delivery for the MQTT messages (defaults to the lowest quality).
azureCertX509CertificateAzure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(string, string, string, string, MqttQoSLevel, byte[], string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, string moduleId, string sasKey, MqttQoSLevel qosLevel = MqttQoSLevel.AtLeastOnce, byte[] azureCert = null, string modelId = null)
Parameters
iotHubNamestringThe Azure IoT name fully qualified (ex: youriothub.azure-devices.net).
deviceIdstringThe device ID which is the name of your device.
moduleIdstringThe module ID which is attached to the device ID.
sasKeystringOne of the SAS Key either primary, either secondary.
qosLevelMqttQoSLevelThe default quality level delivery for the MQTT messages, default to the lower quality.
azureCertbyte[]Azure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(string, string, string, string, MqttQoSLevel, X509Certificate, string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, string moduleId, string sasKey, MqttQoSLevel qosLevel = MqttQoSLevel.AtLeastOnce, X509Certificate azureCert = null, string modelId = null)
Parameters
iotHubNamestringThe Azure IoT name fully qualified (ex: youriothub.azure-devices.net).
deviceIdstringThe device ID which is the name of your device.
moduleIdstringThe module ID which is attached to the device ID.
sasKeystringOne of the SAS Key either primary, either secondary.
qosLevelMqttQoSLevelThe default quality level delivery for the MQTT messages, default to the lower quality.
azureCertX509CertificateAzure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(string, string, string, MqttQoSLevel, byte[], string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, string sasKey, MqttQoSLevel qosLevel = MqttQoSLevel.AtLeastOnce, byte[] azureCert = null, string modelId = null)
Parameters
iotHubNamestringThe Azure IoT name fully qualified (ex: youriothub.azure-devices.net).
deviceIdstringThe device ID which is the name of your device.
sasKeystringOne of the SAS Key either primary, either secondary.
qosLevelMqttQoSLevelThe default quality level delivery for the MQTT messages, default to the lower quality.
azureCertbyte[]Azure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(string, string, string, MqttQoSLevel, X509Certificate, string)
Creates an DeviceClient class.
public DeviceClient(string iotHubName, string deviceId, string sasKey, MqttQoSLevel qosLevel = MqttQoSLevel.AtLeastOnce, X509Certificate azureCert = null, string modelId = null)
Parameters
iotHubNamestringThe Azure IoT name fully qualified (ex: youriothub.azure-devices.net).
deviceIdstringThe device ID which is the name of your device.
sasKeystringOne of the SAS Key either primary, either secondary.
qosLevelMqttQoSLevelThe default quality level delivery for the MQTT messages, default to the lower quality.
azureCertX509CertificateAzure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(IMqttClient, string, string, byte[], MqttQoSLevel, byte[], string)
Creates an DeviceClient class.
public DeviceClient(IMqttClient mqttc, string iotHubName, string deviceId, byte[] clientCert = null, MqttQoSLevel qosLevel = MqttQoSLevel.AtMostOnce, byte[] azureCert = null, string modelId = null)
Parameters
mqttcIMqttClientThe MQTT client to use.
iotHubNamestringYour Azure IoT Hub fully qualified domain name (example: youriothub.azure-devices.net).
deviceIdstringThe device ID (name of your device).
clientCertbyte[]The certificate to connect the device (containing both public and private keys). Pass null if you are using the certificate store on the device.
qosLevelMqttQoSLevelThe default quality of assurance level for delivery for the MQTT messages (defaults to the lowest quality).
azureCertbyte[]Azure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
DeviceClient(IMqttClient, string, string, string, MqttQoSLevel, byte[], string)
Creates an DeviceClient class.
public DeviceClient(IMqttClient mqttc, string iotHubName, string deviceId, string sasKey, MqttQoSLevel qosLevel = MqttQoSLevel.AtLeastOnce, byte[] azureCert = null, string modelId = null)
Parameters
mqttcIMqttClientThe MQTT client to use.
iotHubNamestringThe Azure IoT name fully qualified (ex: youriothub.azure-devices.net).
deviceIdstringThe device ID which is the name of your device.
sasKeystringOne of the SAS Key either primary, either secondary.
qosLevelMqttQoSLevelThe default quality level delivery for the MQTT messages, default to the lower quality.
azureCertbyte[]Azure certificate for the connection to Azure IoT Hub.
modelIdstringAzure Plug and Play model ID.
Properties
IoTHubStatus
The latest status.
public IoTHubStatus IoTHubStatus { get; }
Property Value
IsConnected
True if the device connected.
public bool IsConnected { get; }
Property Value
LastTwin
The latest Twin received.
public Twin LastTwin { get; }
Property Value
ModelId
Azure Plug and Play model ID.
public string ModelId { get; }
Property Value
ModuleId
The module ID attached to the device ID.
public string ModuleId { get; }
Property Value
QosLevel
The default level quality.
public MqttQoSLevel QosLevel { get; set; }
Property Value
Methods
AddMethodCallback(MethodCallback)
Add a callback method.
public void AddMethodCallback(MethodCallback methodCallback)
Parameters
methodCallbackMethodCallbackThe callback method to add.
Close()
Close the connection with Azure IoT and disconnect the device.
public void Close()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetTwin(CancellationToken)
Gets the twin.
public Twin GetTwin(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA cancellation token.
Returns
- Twin
The twin.
Remarks
It is strongly recommended to use a cancellation token that can be canceled and manage this on the caller code level. A reasonable time of few seconds is recommended with a retry mechanism.
Open()
Open the connection with Azure IoT. This will initiate a connection from the device to the Azure IoT Hub instance.
public bool Open()
Returns
- bool
True if open.
Reconnect()
Reconnect to Azure Iot Hub.
public void Reconnect()
RemoveMethodCallback(MethodCallback)
Remove a callback method.
public void RemoveMethodCallback(MethodCallback methodCallback)
Parameters
methodCallbackMethodCallbackThe callback method to remove.
SendMessage(string, string, ArrayList, CancellationToken, string)
Send a message to Azure IoT.
public bool SendMessage(string message, string contentType, ArrayList userProperties, CancellationToken cancellationToken = default, string dtdlComponentname = "")
Parameters
messagestringThe message to send.
contentTypestringContent of the application message.
userPropertiesArrayListUser properties to add to the application message.
cancellationTokenCancellationTokenA cancellation token. If you use the default one, the confirmation of delivery will not be awaited.
dtdlComponentnamestringThe DTDL component name.
Returns
- bool
True for successful message delivery.
SendMessage(string, string, CancellationToken)
Send a message to Azure IoT.
public bool SendMessage(string message, string contentType, CancellationToken cancellationToken = default)
Parameters
messagestringThe message to send.
contentTypestringContent of the application message.
cancellationTokenCancellationTokenA cancellation token. If you use the default one, the confirmation of delivery will not be awaited.
Returns
- bool
True for successful message delivery.
SendMessage(string, CancellationToken, string)
Send a message to Azure IoT.
public bool SendMessage(string message, CancellationToken cancellationToken = default, string dtdlComponentname = "")
Parameters
messagestringThe message to send.
cancellationTokenCancellationTokenA cancellation token. If you use the default one, the confirmation of delivery will not be awaited.
dtdlComponentnamestringThe DTDL component name.
Returns
- bool
True for successful message delivery.
UpdateReportedProperties(TwinCollection, CancellationToken)
Update the twin reported properties.
public bool UpdateReportedProperties(TwinCollection reported, CancellationToken cancellationToken = default)
Parameters
reportedTwinCollectionThe reported properties.
cancellationTokenCancellationTokenA cancellation token. If you use the default one, the confirmation of delivery will not be awaited.
Returns
- bool
True for successful message delivery.
Events
CloudToDeviceMessage
Cloud to device message received event.
public event CloudToDeviceMessage CloudToDeviceMessage
Event Type
StatusUpdated
Status change event.
public event StatusUpdated StatusUpdated
Event Type
TwinUpdated
Device twin updated event.
public event TwinUpdated TwinUpdated