Skip to main content

Mqtt Class

NuGet: GHIElectronics.TinyCLR.Networking.Mqtt
Assembly: GHIElectronics.TinyCLR.Networking.Mqtt
Namespace: GHIElectronics.TinyCLR.Networking.Mqtt

MQTT client. Construct with an MqttClientSetting, call Connect with an MqttConnectionSetting, subscribe to topics, and publish messages. Asynchronous events deliver inbound traffic.

public class Mqtt

Constructors

Mqtt(MqttClientSetting setting)

public Mqtt(MqttClientSetting setting)

Creates a new MQTT client using the given transport settings.

Properties

IsConnected

public bool IsConnected { get; set; }

Gets whether the client is currently connected to the broker.

ClientId

public string ClientId { get; }

Gets the client identifier of the current connection.

ClientSetting

public MqttClientSetting ClientSetting { get; }

Gets the transport-level settings the client was created with.

ConnectionSetting

public MqttConnectionSetting ConnectionSetting { get; set; }

Gets the per-session settings used for the current connection.

Methods

Connect(MqttConnectionSetting setting)

public ConnectReturnCode Connect(MqttConnectionSetting setting)

Connects to the broker using the given session settings and returns the broker's response code.

Returns ConnectReturnCode

Disconnect()

public void Disconnect()

Sends a disconnect request to the broker and closes the connection.

Subscribe(string[] topics, QoSLevel[] qosLevels, ushort packetId)

public void Subscribe(string[] topics, QoSLevel[] qosLevels, ushort packetId)

Subscribes to the given topics at the specified quality-of-service levels.

Unsubscribe(string[] topics, ushort packetId)

public void Unsubscribe(string[] topics, ushort packetId)

Unsubscribes from the given topics.

Publish(string topic, byte[] data, QoSLevel qosLevel, bool retain, ushort packetId)

public void Publish(string topic, byte[] data, QoSLevel qosLevel, bool retain, ushort packetId)

Publishes a message to a topic at the specified quality-of-service level.

Events

PublishReceivedChanged

public event PublishReceivedEventHandler PublishReceivedChanged

Raised when a message is received on a subscribed topic.

PublishedChanged

public event PublishedEventHandler PublishedChanged

Raised when a published message is acknowledged.

SubscribedChanged

public event SubscribedEventHandler SubscribedChanged

Raised when a subscribe request is acknowledged.

UnsubscribedChanged

public event UnsubscribedEventHandler UnsubscribedChanged

Raised when an unsubscribe request is acknowledged.

ConnectedChanged

public event ConnectedEventHandler ConnectedChanged

Raised when the connection to the broker is established or closed.