Class MqttConnectionClient
- Namespace
- nanoFramework.Aws.IoTCore.Devices
- Assembly
- nanoFramework.Aws.IoTCore.Devices.dll
AWS IoT Core MQTT Connection Client for .NET nanoFramework
public class MqttConnectionClient : IDisposable
- Inheritance
-
MqttConnectionClient
- Implements
- Inherited Members
- Extension Methods
Remarks
Further documentation: https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Services/IotData/Generated/_netstandard/AmazonIotDataClient.cs https://github.com/aws/aws-iot-device-sdk-embedded-C/tree/master/src https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-mqtt.html
Constructors
MqttConnectionClient(string, string, X509Certificate2, QoSLevel, X509Certificate)
Creates an MqttConnectionClient class.
public MqttConnectionClient(string iotCoreUri, string uniqueId, X509Certificate2 clientCert, MqttConnectionClient.QoSLevel qosLevel = QoSLevel.AtMostOnce, X509Certificate awsRootCert = null)
Parameters
iotCoreUristringThe AWS IoT Core fully qualified domain name (example: 'instance'.'region'.amazonaws.com)
uniqueIdstringA unique identity for your device (Device ID / Thing Name).
clientCertX509Certificate2The certificate used to connect the device to the MQTT broker (containing both the private certificate and private key).
qosLevelMqttConnectionClient.QoSLevelThe default quality of service level for the delivery of MQTT messages, (defaults to the lowest quality)
awsRootCertX509CertificateThe Root (AWS) certificate for the connection to AWS IoT Core
Properties
ConnectionStatus
The latest connection status.
public ConnectorState ConnectionStatus { get; }
Property Value
IsConnected
True if the device connected successfully.
public bool IsConnected { get; }
Property Value
LastShadow
The latest Shadow received.
public Shadow LastShadow { get; }
Property Value
QosLevel
The default quality of service level.
public MqttQoSLevel QosLevel { get; set; }
Property Value
ThingName
The name of the "Thing"
public string ThingName { get; }
Property Value
Remarks
Otherwise known as the "clienttoken" or "Device ID"
Methods
Close()
Close the connection with AWS IoT Core MQTT and disconnect the device.
public void Close()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetShadow(CancellationToken, string)
Gets the device shadow.
public Shadow GetShadow(CancellationToken cancellationToken = default, string namedShadow = "")
Parameters
cancellationTokenCancellationTokenA cancellation token
namedShadowstringA named shadow
Returns
- Shadow
The shadow.
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 AWS IoT Core. This will connect AWS IoT Core (via MQTT) to the device.
public bool Open()
Returns
- bool
True for a successful connection
Open(string)
Overrides the default topic prefix of "device"
public bool Open(string topicPrefix)
Parameters
topicPrefixstringThe topic prefix for telemetry, device messages and LWT.
Returns
- bool
True for a successful connection
Open(string, string, string)
Overrides the default connection topics
public bool Open(string telemetryTopic, string deviceMessageTopic, string lwtTopic)
Parameters
telemetryTopicstringThe telemetry topic
deviceMessageTopicstringThe device message topic
lwtTopicstringThe last will and testament topic
Returns
- bool
True for a successful connection
Reconnect()
Reconnect to AWS Iot Core MQTT.
public void Reconnect()
SendMessage(string, CancellationToken)
Send a message to Aws IoT Core.
public bool SendMessage(string message, CancellationToken cancellationToken = default)
Parameters
messagestringThe message to send.
cancellationTokenCancellationTokenA cancellation token. If you use the default one, the confirmation of delivery will not be awaited.
Returns
- bool
True for successful message delivery.
UpdateReportedState(Shadow, CancellationToken, string)
Update the device shadow reported state.
public bool UpdateReportedState(Shadow shadowToSend, CancellationToken cancellationToken = default, string namedShadow = "")
Parameters
shadowToSendShadowThe Shadow to send.
cancellationTokenCancellationTokenA cancellation token. If you use the default one, the confirmation of delivery will not be awaited.
namedShadowstringThe supplementary Shadow name.
Returns
- bool
True for successful message delivery.
Events
CloudToDeviceMessage
Cloud to device message received event.
public event CloudToDeviceMessage CloudToDeviceMessage
Event Type
ShadowUpdated
Device shadow updated event.
public event ShadowUpdated ShadowUpdated
Event Type
StatusUpdated
Status change event.
public event StatusUpdated StatusUpdated