Skip to content

Commit fc98833

Browse files
committed
Basic MQTT Client working
1 parent 05c2841 commit fc98833

6 files changed

+46
-3
lines changed

makeosxbundle.sh

100755100644
File mode changed.

qt-openzwave.pri

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ win32 {
5555
} else {
5656
equals(BUILDTYPE, "debug") {
5757
exists ( $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL/OpenZWaved.dll )) {
58-
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL) -lopenzwaved
58+
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL) -lOpenZWaved
5959
OZW_LIB_PATH = $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/ReleaseDLL)
6060
} else {
6161
error("Can't find a copy of OpenZWaved.dll in the DebugDLL Directory");

qt-ozwdaemon/qt-ozwdaemon.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
QT -= gui
22

3-
QT += remoteobjects
3+
QT += remoteobjects mqtt
44

55
TARGET = ../ozwdaemon
66

qt-ozwdaemon/qtozwdaemon.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
#include <QtDebug>
22
#include "qtozwdaemon.h"
33

4+
45
qtozwdaemon::qtozwdaemon(QObject *parent) : QObject(parent)
56
{
67
this->m_openzwave = new QTOpenZwave(this);
78
this->m_qtozwmanager = this->m_openzwave->GetManager();
89
QObject::connect(this->m_qtozwmanager, &QTOZWManager::ready, this, &qtozwdaemon::QTOZW_Ready);
910
this->m_qtozwmanager->initilizeSource(true);
11+
12+
this->m_client = new QMqttClient(this);
13+
this->m_client->setHostname("10.51.107.19");
14+
this->m_client->setPort(1883);
15+
16+
connect(this->m_client, &QMqttClient::stateChanged, this, &qtozwdaemon::updateLogStateChange);
17+
connect(this->m_client, &QMqttClient::disconnected, this, &qtozwdaemon::brokerDisconnected);
18+
19+
connect(this->m_client, &QMqttClient::messageReceived, this, &qtozwdaemon::handleMessage);
20+
connect(m_client, &QMqttClient::pingResponseReceived, this, [this]() {
21+
const QString content = QDateTime::currentDateTime().toString()
22+
+ QLatin1String(" PingResponse")
23+
+ QLatin1Char('\n');
24+
qDebug() << content;
25+
});
26+
this->m_client->connectToHost();
1027
}
1128

1229
void qtozwdaemon::QTOZW_Ready() {
@@ -19,3 +36,25 @@ void qtozwdaemon::startOZW() {
1936
}
2037
//this->m_qtozwmanager->open(this->getSerialPort());
2138
}
39+
40+
void qtozwdaemon::updateLogStateChange()
41+
{
42+
const QString content = QDateTime::currentDateTime().toString()
43+
+ QLatin1String(": State Change: " )
44+
+ QString::number(m_client->state());
45+
qDebug() << content;
46+
if (this->m_client->state() == QMqttClient::ClientState::Connected) {
47+
this->m_client->subscribe(QMqttTopicFilter("/OpenZWave/commands"));
48+
this->m_client->publish(QMqttTopicName("/OpenZWave/commands"), QString("testhaha").toLocal8Bit());
49+
}
50+
51+
}
52+
53+
void qtozwdaemon::brokerDisconnected()
54+
{
55+
qDebug() << "Disconnnected";
56+
}
57+
58+
void qtozwdaemon::handleMessage(const QByteArray &message, const QMqttTopicName &topic) {
59+
qDebug() << "Received: " << topic.name() << ":" << message;
60+
}

qt-ozwdaemon/qtozwdaemon.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <QObject>
55
#include <QString>
6+
#include <QtMqtt/QMqttClient>
67

78
#include <qt-openzwave/qtopenzwave.h>
89
#include <qt-openzwave/qtozwmanager.h>
@@ -22,12 +23,15 @@ class qtozwdaemon : public QObject
2223

2324
public slots:
2425
void QTOZW_Ready();
25-
26+
void updateLogStateChange();
27+
void brokerDisconnected();
28+
void handleMessage(const QByteArray &message, const QMqttTopicName &topic = QMqttTopicName());
2629

2730
private:
2831
QTOpenZwave *m_openzwave;
2932
QTOZWManager *m_qtozwmanager;
3033
QString m_serialPort;
34+
QMqttClient *m_client;
3135
};
3236

3337
#endif // QTOZWDAEMON_H

updaterpath.sh

100755100644
File mode changed.

0 commit comments

Comments
 (0)