-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnmqtt_listener.h
62 lines (42 loc) · 1.29 KB
/
nmqtt_listener.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
nmqtt_listener.h - Header file for the NmqttListener class.
Revision 0
Notes:
-
2019/06/27, Maya Posch
*/
#ifndef NMQTTLISTENER_H
#define NMQTTLISTENER_H
#include <string>
#include <nymphmqtt/client.h>
#include <QObject>
class NmqttListener : public QObject {
Q_OBJECT
NmqttClient client;
int handle;
QString host;
int port;
void messageHandler(int handle, std::string topic, std::string payload);
void logHandler(int level, std::string text);
public:
explicit NmqttListener(QObject *parent = 0);
~NmqttListener();
bool init(QString clientId = "CC-UI", QString host = "localhost", int port = 1883);
public slots:
bool setTLS(std::string &ca, std::string &cert, std::string &key);
bool setPassword(std::string &username, std::string &password);
void publishMessage(std::string topic, std::string msg, uint8_t qos = 0, bool retain = false);
void addSubscription(std::string topic);
void removeSubscription(std::string topic);
signals:
void connected();
void newBrokerConnection(NmqttBrokerConnection conn);
void failed(QString err);
void receivedMessage(std::string topic, std::string message);
void finished();
public slots:
void connectBroker();
void disconnectBroker();
};
Q_DECLARE_METATYPE(NmqttBrokerConnection);
#endif