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
clientIdstringClient identifier.
usernamestringUsername.
passwordstringPassword.
willRetainboolWill retain flag.
willQosLevelMqttQoSLevelWill QOS level.
willFlagboolWill flag.
willTopicstringWill topic.
willMessagestringWill message.
cleanSessionboolClean sessione flag.
keepAlivePeriodushortKeep 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
brokerHostNamestringBroker Host Name or IP Address
brokerPortintBroker port
secureboolUsing secure connection
caCertbyte[]CA certificate for secure connection
clientCertbyte[]Client certificate
sslProtocolMqttSslProtocolsSSL/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
topicstringMessage topic.
messagebyte[]Message data (payload).
contentTypestringContent 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
topicstringMessage topic.
messagebyte[]Message data (payload).
contentTypestringContent of the application message. This is only available for MQTT v5.0.
userPropertiesArrayListUser properties for the application message. This is only available for MQTT v5.0.
qosLevelMqttQoSLevelQoS Level.
retainboolRetain flag.
Returns
- ushort
Message Id related to PUBLISH message.
Exceptions
- ArgumentException
If
userPropertieselements 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
topicsstring[]List of topics to subscribe.
qosLevelsMqttQoSLevel[]QOS levels related to topics.
Returns
- ushort
Message Id related to SUBSCRIBE message.
Unsubscribe(string[])
Unsubscribe for message topics.
ushort Unsubscribe(string[] topics)
Parameters
topicsstring[]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