Add Mqtt item
This commit is contained in:
parent
0fd50eb227
commit
eb60f85604
19 changed files with 901 additions and 48 deletions
40
src/mqttclient.h
Normal file
40
src/mqttclient.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef MQTTCLIENT_H
|
||||
#define MQTTCLIENT_H
|
||||
|
||||
#include <QMqttClient>
|
||||
#include <QObject>
|
||||
#include <QJsonObject>
|
||||
#include <map>
|
||||
|
||||
class MqttClient: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
struct Subscription
|
||||
{
|
||||
int ref;
|
||||
QMqttSubscription* subscription;
|
||||
};
|
||||
|
||||
private:
|
||||
QString baseTopicName;
|
||||
std::shared_ptr<QMqttClient> client;
|
||||
std::map<QString, Subscription*> subscriptions;
|
||||
|
||||
private slots:
|
||||
void onClientStateChanged(QMqttClient::ClientState state);
|
||||
void onClientError(QMqttClient::ClientError error);
|
||||
|
||||
public:
|
||||
explicit MqttClient();
|
||||
~MqttClient();
|
||||
void start(const QJsonObject& settings);
|
||||
void store(QJsonObject& json);
|
||||
std::shared_ptr<QMqttClient> getClient();
|
||||
Subscription* subscribe(QString topic);
|
||||
void unsubscribe(Subscription* subscription);
|
||||
void unsubscribe(QString topic);
|
||||
QString getBaseTopic();
|
||||
};
|
||||
|
||||
#endif // MQTTCLIENT_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue