|
kmMqtt 0.0.1
MQTT Client Library
|
A high-level MQTT client interface for managing MQTT connections, publishing, subscribing, and handling events. More...
#include <MqttClient.h>
Public Member Functions | |
| MqttClient () | |
| Constructs a default MqttClient instance. | |
| MqttClient (const IMqttEnvironment *const env, const MqttClientOptions &clientOptions) | |
| Constructs an MqttClient instance with a custom environment and options. | |
| ~MqttClient () | |
| Destructor for the MqttClient class. | |
| ReqResult | connect (ConnectArgs &&args, ConnectAddress &&address) noexcept |
| Connects to the MQTT broker using the provided connection arguments and address. | |
| ReqResult | publish (const char *topic, ByteBuffer &&payload, PublishOptions &&options) noexcept |
| Publishes a message to a specified topic with the given payload and options. | |
| ReqResult | subscribe (const std::vector< Topic > &topics, SubscribeOptions &&options) noexcept |
| Subscribe to the specified topics with the given subscribe options. | |
| ReqResult | unSubscribe (const std::vector< Topic > &topics, UnSubscribeOptions &&options) noexcept |
| Unsubscribe from the specified topics with the given unsubscribe options. | |
| ReqResult | disconnect (DisconnectArgs &&args={}) noexcept |
| Disconnects from the MQTT broker using the provided disconnect arguments. | |
| ClientError | shutdown () noexcept |
| Shuts down the MQTT client, releasing all resources and stopping any ongoing operations. | |
| ClientError | tick () noexcept |
| Ticks the MQTT client to process incoming and outgoing messages and events. | |
| ErrorEvent & | onErrorEvent () noexcept |
| Accessor for the ErrorEvent. | |
| ConnectEvent & | onConnectEvent () noexcept |
| Accessor for the ConnectEvent. | |
| DisconnectEvent & | onDisconnectEvent () noexcept |
| Accessor for the DisconnectEvent. | |
| ReconnectEvent & | onReconnectEvent () noexcept |
| Accessor for the ReconnectEvent. | |
| PublishEvent & | onPublishEvent () noexcept |
| Accessor for the PublishEvent (receiving publish message from broker). | |
| PublishCompletedEvent & | onPublishCompletedEvent () noexcept |
| Accessor for the PublishCompletedEvent. | |
| SubscribeAckEvent & | onSubscribeAckEvent () noexcept |
| Accessor for the SubscribeAckEvent. | |
| UnSubscribeAckEvent & | onUnSubscribeAckEvent () noexcept |
| Accessor for the UnSubscribeAckEvent. | |
| ConnectionStatus | getConnectionStatus () const noexcept |
| Get the connection status of the MQTT client. | |
| const MqttConnectionInfo & | getConnectionInfo () const noexcept |
| Get the info of the current MQTT connection. | |
| bool | getIsTickAsync () const noexcept |
| Check if the client is configured for asynchronous ticking. | |
A high-level MQTT client interface for managing MQTT connections, publishing, subscribing, and handling events.
This class provides an abstraction for interacting with an MQTT broker. It supports connecting to the broker, publishing messages, subscribing to topics, and handling various MQTT events. The implementation details are encapsulated in the MqttClientImpl class.
| kmMqtt::mqtt::MqttClient::MqttClient | ( | ) |
Constructs a default MqttClient instance.
This constructor initializes the MQTT client with a default environment and options. It creates an instance of MqttClientImpl and manages its lifecycle.
| kmMqtt::mqtt::MqttClient::MqttClient | ( | const IMqttEnvironment *const | env, |
| const MqttClientOptions & | clientOptions ) |
Constructs an MqttClient instance with a custom environment and options.
This constructor allows the user to specify a custom environment and options for the MQTT client. If the client options specify asynchronous ticking, the client will start ticking asynchronously.
| env | A pointer to the custom MQTT environment. |
| clientOptions | The options for configuring the MQTT client. |
| kmMqtt::mqtt::MqttClient::~MqttClient | ( | ) |
Destructor for the MqttClient class.
Cleans up resources and ensures proper shutdown of the MQTT client. Safe to call without shutdown() first.
|
noexcept |
Connects to the MQTT broker using the provided connection arguments and address.
| args | The connection arguments for establishing the MQTT connection. |
| address | The address of the MQTT broker to connect to. |
|
noexcept |
Disconnects from the MQTT broker using the provided disconnect arguments.
| args | The disconnect arguments for terminating the MQTT connection. |
|
noexcept |
Get the info of the current MQTT connection.
|
noexcept |
Get the connection status of the MQTT client.
|
noexcept |
Check if the client is configured for asynchronous ticking.
|
noexcept |
Accessor for the ConnectEvent.
Invoked when the client successfully connects to the MQTT broker. Invoked when the client fails to connect to the MQTT broker on initial connect call. Contains ConnectAck information if available.
|
noexcept |
Accessor for the DisconnectEvent.
Invoked when the client disconnects from the MQTT broker. Invoked when the client fails to reconnect to the MQTT broker after an unexpected disconnection. Is not invoked as part of connect failure handling. Is not invoked as part of reconnection handling unless reconnection fails.
|
noexcept |
Accessor for the ErrorEvent.
Invoked when an error occurs within the MQTT client.
|
noexcept |
Accessor for the PublishCompletedEvent.
Invoked when a packet for publish acknowledged, release, received, or complete is received from the broker for a sent publish packet. Notifies of the general state of the publish process for its corresponding QOS level. Does not call back on QOS 0 publishes.
|
noexcept |
Accessor for the PublishEvent (receiving publish message from broker).
Invoked when a publish message is received for a subscribed topic.
|
noexcept |
Accessor for the ReconnectEvent.
Invoked when the client successfully reconnects to the MQTT broker after an unexpected disconnection. Invoked when reconnection starts after an unexpected disconnection.
|
noexcept |
Accessor for the SubscribeAckEvent.
Invoked when a subscribe acknowledgment is received from the broker for a sent subscribe packet.
|
noexcept |
Accessor for the UnSubscribeAckEvent.
Invoked when an unsubscribe acknowledgment is received from the broker for a sent unsubscribe packet.
|
noexcept |
Publishes a message to a specified topic with the given payload and options.
| topic | The topic to which the message will be published. |
| payload | The payload of the message to be published. |
| options | The options for publishing the message. |
|
noexcept |
Shuts down the MQTT client, releasing all resources and stopping any ongoing operations.
Use this for both in synchronous and asynchronous modes.
|
noexcept |
|
noexcept |
Ticks the MQTT client to process incoming and outgoing messages and events.
Use this method in synchronous mode to keep the client responsive. It's an error to call this method if the client is configured for asynchronous ticking.
|
noexcept |
Unsubscribe from the specified topics with the given unsubscribe options.
| topics | The topics from which the client is unsubscribing. |
| options | The unsubscribe options. |