Table of Contents

Interface IMqttClient

Namespace
nanoFramework.M2Mqtt
Assembly
nanoFramework.M2Mqtt.Core.dll

Interface for MQTT client.

public interface IMqttClient
Extension Methods

Remarks

This is compatible with the full nanoFramceork M2Mqtt client. But the implementation is different. The change of the nanoFramework M2Mqtt client is not done yet. Once done, this interface will be removed and replaced by a reference to the core nanoFramework M2Mqtt client nuget containing the core elements. In the longer term, this will allow to use higher level classes like Azure or AWS in a full transparent way.

Properties

IsConnected

Gets a value indicating whether the connection status between client and broker.

bool IsConnected { get; }

Property Value

bool

Methods

Close()

Close client

void Close()

Connect(string, string, string, bool, MqttQoSLevel, bool, string, string, bool, ushort)

Connect to broker.

MqttReasonCode Connect(string clientId, string username, string password, bool willRetain, MqttQoSLevel willQosLevel, bool willFlag, string willTopic, string willMessage, bool cleanSession, ushort keepAlivePeriod)

Parameters

clientId string

Client identifier.

username string

Username.

password string

Password.

willRetain bool

Will retain flag.

willQosLevel MqttQoSLevel

Will QOS level.

willFlag bool

Will flag.

willTopic string

Will topic.

willMessage string

Will message.

cleanSession bool

Clean sessione flag.

keepAlivePeriod ushort

Keep alive period.

Returns

MqttReasonCode

Return code of CONNACK message from broker.

Disconnect()

Disconnect from broker.

void Disconnect()

Init(string, int, bool, byte[], byte[], MqttSslProtocols)

MqttClient initialization

void Init(string brokerHostName, int brokerPort, bool secure, byte[] caCert, byte[] clientCert, MqttSslProtocols sslProtocol)

Parameters

brokerHostName string

Broker Host Name or IP Address

brokerPort int

Broker port

secure bool

Using secure connection

caCert byte[]

CA certificate for secure connection

clientCert byte[]

Client certificate

sslProtocol MqttSslProtocols

SSL/TLS protocol version

Publish(string, byte[])

Publish a message asynchronously (QoS Level AtMostOnce and not retained).

ushort Publish(string topic, byte[] message)

Parameters

topic string

Message topic.

message byte[]

Message data (payload).

Returns

ushort

Message Id related to PUBLISH message.

Publish(string, byte[], string)

Publish a message asynchronously (QoS Level AtMostOnce and not retained).

ushort Publish(string topic, byte[] message, string contentType)

Parameters

topic string

Message topic.

message byte[]

Message data (payload).

contentType string

Content of the application message. This is only available for MQTT v5.0.

Returns

ushort

Message Id related to PUBLISH message.

Exceptions

NotSupportedException

If setting a parameter that is not supported in the MQTT version set for this IMqttClient.

Publish(string, byte[], string, ArrayList, MqttQoSLevel, bool)

Publish a message asynchronously.

ushort Publish(string topic, byte[] message, string contentType, ArrayList userProperties, MqttQoSLevel qosLevel, bool retain)

Parameters

topic string

Message topic.

message byte[]

Message data (payload).

contentType string

Content of the application message. This is only available for MQTT v5.0.

userProperties ArrayList

User properties for the application message. This is only available for MQTT v5.0.

qosLevel MqttQoSLevel

QoS Level.

retain bool

Retain flag.

Returns

ushort

Message Id related to PUBLISH message.

Exceptions

ArgumentException

If userProperties elements aren't of type UserProperty.

NotSupportedException

If setting a parameter that is not supported in the MQTT version set for this IMqttClient.

Subscribe(string[], MqttQoSLevel[])

Subscribe for message topics.

ushort Subscribe(string[] topics, MqttQoSLevel[] qosLevels)

Parameters

topics string[]

List of topics to subscribe.

qosLevels MqttQoSLevel[]

QOS levels related to topics.

Returns

ushort

Message Id related to SUBSCRIBE message.

Unsubscribe(string[])

Unsubscribe for message topics.

ushort Unsubscribe(string[] topics)

Parameters

topics string[]

List of topics to unsubscribe.

Returns

ushort

Message Id in UNSUBACK message from broker.

Events

ConnectionClosed

The event for peer/client disconnection.

event IMqttClient.ConnectionClosedEventHandler ConnectionClosed

Event Type

IMqttClient.ConnectionClosedEventHandler

MqttMsgPublishReceived

The event for PUBLISH message received.

event IMqttClient.MqttMsgPublishEventHandler MqttMsgPublishReceived

Event Type

IMqttClient.MqttMsgPublishEventHandler

MqttMsgPublished

The event for published message.

event IMqttClient.MqttMsgPublishedEventHandler MqttMsgPublished

Event Type

IMqttClient.MqttMsgPublishedEventHandler

MqttMsgSubscribed

The event for subscribed topic.

event IMqttClient.MqttMsgSubscribedEventHandler MqttMsgSubscribed

Event Type

IMqttClient.MqttMsgSubscribedEventHandler

MqttMsgUnsubscribed

The event for unsubscribed topic.

event IMqttClient.MqttMsgUnsubscribedEventHandler MqttMsgUnsubscribed

Event Type

IMqttClient.MqttMsgUnsubscribedEventHandler