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
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
stringClient identifier.
username
stringUsername.
password
stringPassword.
willRetain
boolWill retain flag.
willQosLevel
MqttQoSLevelWill QOS level.
willFlag
boolWill flag.
willTopic
stringWill topic.
willMessage
stringWill message.
cleanSession
boolClean sessione flag.
keepAlivePeriod
ushortKeep 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
stringBroker Host Name or IP Address
brokerPort
intBroker port
secure
boolUsing secure connection
caCert
byte[]CA certificate for secure connection
clientCert
byte[]Client certificate
sslProtocol
MqttSslProtocolsSSL/TLS protocol version
Publish(string, byte[])
Publish a message asynchronously (QoS Level AtMostOnce and not retained).
ushort Publish(string topic, byte[] message)
Parameters
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
stringMessage topic.
message
byte[]Message data (payload).
contentType
stringContent 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
stringMessage topic.
message
byte[]Message data (payload).
contentType
stringContent of the application message. This is only available for MQTT v5.0.
userProperties
ArrayListUser properties for the application message. This is only available for MQTT v5.0.
qosLevel
MqttQoSLevelQoS Level.
retain
boolRetain 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
MqttMsgPublishReceived
The event for PUBLISH message received.
event IMqttClient.MqttMsgPublishEventHandler MqttMsgPublishReceived
Event Type
MqttMsgPublished
The event for published message.
event IMqttClient.MqttMsgPublishedEventHandler MqttMsgPublished
Event Type
MqttMsgSubscribed
The event for subscribed topic.
event IMqttClient.MqttMsgSubscribedEventHandler MqttMsgSubscribed
Event Type
MqttMsgUnsubscribed
The event for unsubscribed topic.
event IMqttClient.MqttMsgUnsubscribedEventHandler MqttMsgUnsubscribed