MQTT client wrapper providing connection management, auto-reconnect, and SSL support.
More...
#include <mqttclient.h>
|
|
void | clientConnected () |
| | Emitted when the client connects to the broker.
|
| |
|
void | clientDisconnected () |
| | Emitted when the client disconnects from the broker.
|
| |
| void | clientError (QMqttClient::ClientError error) |
| | Emitted when a client error occurs.
|
| |
|
| | MqttClient (QObject *parent=nullptr) |
| | Construct an MqttClient with default parameters.
|
| |
| | MqttClient (const MqttParameters ¶meters, QObject *parent=nullptr) |
| | Construct an MqttClient with the given MQTT parameters.
|
| |
|
virtual | ~MqttClient () |
| | Destroy the MqttClient and release resources.
|
| |
|
virtual void | start () |
| | Start the MQTT client and optionally connect to the broker.
|
| |
|
virtual void | stop () |
| | Stop the MQTT client and disconnect from the broker.
|
| |
| MqttParameters | parameters () const |
| | Get the current MQTT connection parameters.
|
| |
| void | setParameters (const MqttParameters &value) |
| | Set the MQTT connection parameters.
|
| |
| bool | connectAtStart () const |
| | Get whether the client connects automatically when started.
|
| |
| void | setConnectAtStart (bool value) |
| | Set whether the client connects automatically when started.
|
| |
| bool | autoReconnect () const |
| | Get whether automatic reconnection is enabled.
|
| |
| void | setAutoReconnect (bool value) |
| | Set whether automatic reconnection is enabled.
|
| |
| TimeSpan | autoReconnectTime () const |
| | Get the delay between automatic reconnection attempts.
|
| |
| void | setAutoReconnectTime (const TimeSpan &value) |
| | Set the delay between automatic reconnection attempts.
|
| |
| QString | clientId () const |
| | Get the MQTT client identifier.
|
| |
| void | setClientId (const QString &value) |
| | Set the MQTT client identifier.
|
| |
| bool | isConnected () const |
| | Check whether the client is currently connected to the broker.
|
| |
| QMqttSubscription * | subscribe (const QString &topic, uint8_t qos=0) |
| | Subscribe to an MQTT topic.
|
| |
| int | publish (const QString &topic, const QByteArray &payload, uint8_t qos=0, bool retain=false) |
| | Publish a message to an MQTT topic.
|
| |
|
| QMqttClient * | client () const |
| | Get the underlying QMqttClient instance.
|
| |
| virtual void | connected () |
| | Called when the client successfully connects to the broker.
|
| |
| virtual void | disconnected () |
| | Called when the client disconnects from the broker.
|
| |
| virtual void | error (QMqttClient::ClientError error) |
| | Called when a client error occurs.
|
| |
MQTT client wrapper providing connection management, auto-reconnect, and SSL support.
Definition at line 11 of file mqttclient.h.
◆ MqttClient() [1/2]
| MqttClient::MqttClient |
( |
QObject * |
parent = nullptr | ) |
|
Construct an MqttClient with default parameters.
- Parameters
-
| parent | The parent QObject. |
◆ MqttClient() [2/2]
| MqttClient::MqttClient |
( |
const MqttParameters & |
parameters, |
|
|
QObject * |
parent = nullptr |
|
) |
| |
Construct an MqttClient with the given MQTT parameters.
- Parameters
-
| parameters | The connection parameters. |
| parent | The parent QObject. |
◆ autoReconnect()
| bool MqttClient::autoReconnect |
( |
| ) |
const |
|
inline |
Get whether automatic reconnection is enabled.
- Returns
- True if auto-reconnect is enabled.
Definition at line 47 of file mqttclient.h.
◆ autoReconnectTime()
| TimeSpan MqttClient::autoReconnectTime |
( |
| ) |
const |
|
inline |
Get the delay between automatic reconnection attempts.
- Returns
- The reconnect interval.
Definition at line 54 of file mqttclient.h.
◆ client()
| QMqttClient * MqttClient::client |
( |
| ) |
const |
|
inlineprotected |
Get the underlying QMqttClient instance.
- Returns
- A pointer to the QMqttClient.
Definition at line 86 of file mqttclient.h.
◆ clientError
| void MqttClient::clientError |
( |
QMqttClient::ClientError |
error | ) |
|
|
signal |
Emitted when a client error occurs.
- Parameters
-
◆ clientId()
| QString MqttClient::clientId |
( |
| ) |
const |
|
inline |
Get the MQTT client identifier.
- Returns
- The client ID string.
Definition at line 61 of file mqttclient.h.
◆ connectAtStart()
| bool MqttClient::connectAtStart |
( |
| ) |
const |
|
inline |
Get whether the client connects automatically when started.
- Returns
- True if auto-connect at start is enabled.
Definition at line 40 of file mqttclient.h.
◆ connected()
| virtual void MqttClient::connected |
( |
| ) |
|
|
inlineprotectedvirtual |
Called when the client successfully connects to the broker.
Definition at line 89 of file mqttclient.h.
◆ disconnected()
| virtual void MqttClient::disconnected |
( |
| ) |
|
|
inlineprotectedvirtual |
Called when the client disconnects from the broker.
Definition at line 91 of file mqttclient.h.
◆ error()
| virtual void MqttClient::error |
( |
QMqttClient::ClientError |
error | ) |
|
|
inlineprotectedvirtual |
Called when a client error occurs.
- Parameters
-
Definition at line 94 of file mqttclient.h.
◆ isConnected()
| bool MqttClient::isConnected |
( |
| ) |
const |
|
inline |
Check whether the client is currently connected to the broker.
- Returns
- True if connected.
Definition at line 68 of file mqttclient.h.
◆ parameters()
Get the current MQTT connection parameters.
- Returns
- The connection parameters.
Definition at line 33 of file mqttclient.h.
◆ publish()
| int MqttClient::publish |
( |
const QString & |
topic, |
|
|
const QByteArray & |
payload, |
|
|
uint8_t |
qos = 0, |
|
|
bool |
retain = false |
|
) |
| |
Publish a message to an MQTT topic.
- Parameters
-
| topic | The topic to publish to. |
| payload | The message payload. |
| qos | The quality-of-service level (0, 1, or 2). |
| retain | True to set the retain flag on the message. |
- Returns
- The packet identifier of the published message, or -1 on failure.
◆ setAutoReconnect()
| void MqttClient::setAutoReconnect |
( |
bool |
value | ) |
|
|
inline |
Set whether automatic reconnection is enabled.
- Parameters
-
| value | True to enable auto-reconnect. |
Definition at line 50 of file mqttclient.h.
◆ setAutoReconnectTime()
| void MqttClient::setAutoReconnectTime |
( |
const TimeSpan & |
value | ) |
|
|
inline |
Set the delay between automatic reconnection attempts.
- Parameters
-
| value | The reconnect interval. |
Definition at line 57 of file mqttclient.h.
◆ setClientId()
| void MqttClient::setClientId |
( |
const QString & |
value | ) |
|
|
inline |
Set the MQTT client identifier.
- Parameters
-
| value | The client ID string. |
Definition at line 64 of file mqttclient.h.
◆ setConnectAtStart()
| void MqttClient::setConnectAtStart |
( |
bool |
value | ) |
|
|
inline |
Set whether the client connects automatically when started.
- Parameters
-
| value | True to enable auto-connect at start. |
Definition at line 43 of file mqttclient.h.
◆ setParameters()
Set the MQTT connection parameters.
- Parameters
-
| value | The connection parameters. |
Definition at line 36 of file mqttclient.h.
◆ subscribe()
| QMqttSubscription * MqttClient::subscribe |
( |
const QString & |
topic, |
|
|
uint8_t |
qos = 0 |
|
) |
| |
Subscribe to an MQTT topic.
- Parameters
-
| topic | The topic filter string. |
| qos | The quality-of-service level (0, 1, or 2). |
- Returns
- A pointer to the resulting QMqttSubscription, or nullptr on failure.
The documentation for this class was generated from the following file: