Basic MQTT Client working

This commit is contained in:
Justin Hammond 2019-10-25 17:35:05 +08:00
parent 05c28412b8
commit fc98833c03
6 changed files with 46 additions and 3 deletions

0
makeosxbundle.sh Executable file → Normal file
View file

View file

@ -55,7 +55,7 @@ win32 {
} else {
equals(BUILDTYPE, "debug") {
exists ( $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL/OpenZWaved.dll )) {
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL) -lopenzwaved
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL) -lOpenZWaved
OZW_LIB_PATH = $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/ReleaseDLL)
} else {
error("Can't find a copy of OpenZWaved.dll in the DebugDLL Directory");

View file

@ -1,6 +1,6 @@
QT -= gui
QT += remoteobjects
QT += remoteobjects mqtt
TARGET = ../ozwdaemon

View file

@ -1,12 +1,29 @@
#include <QtDebug>
#include "qtozwdaemon.h"
qtozwdaemon::qtozwdaemon(QObject *parent) : QObject(parent)
{
this->m_openzwave = new QTOpenZwave(this);
this->m_qtozwmanager = this->m_openzwave->GetManager();
QObject::connect(this->m_qtozwmanager, &QTOZWManager::ready, this, &qtozwdaemon::QTOZW_Ready);
this->m_qtozwmanager->initilizeSource(true);
this->m_client = new QMqttClient(this);
this->m_client->setHostname("10.51.107.19");
this->m_client->setPort(1883);
connect(this->m_client, &QMqttClient::stateChanged, this, &qtozwdaemon::updateLogStateChange);
connect(this->m_client, &QMqttClient::disconnected, this, &qtozwdaemon::brokerDisconnected);
connect(this->m_client, &QMqttClient::messageReceived, this, &qtozwdaemon::handleMessage);
connect(m_client, &QMqttClient::pingResponseReceived, this, [this]() {
const QString content = QDateTime::currentDateTime().toString()
+ QLatin1String(" PingResponse")
+ QLatin1Char('\n');
qDebug() << content;
});
this->m_client->connectToHost();
}
void qtozwdaemon::QTOZW_Ready() {
@ -19,3 +36,25 @@ void qtozwdaemon::startOZW() {
}
//this->m_qtozwmanager->open(this->getSerialPort());
}
void qtozwdaemon::updateLogStateChange()
{
const QString content = QDateTime::currentDateTime().toString()
+ QLatin1String(": State Change: " )
+ QString::number(m_client->state());
qDebug() << content;
if (this->m_client->state() == QMqttClient::ClientState::Connected) {
this->m_client->subscribe(QMqttTopicFilter("/OpenZWave/commands"));
this->m_client->publish(QMqttTopicName("/OpenZWave/commands"), QString("testhaha").toLocal8Bit());
}
}
void qtozwdaemon::brokerDisconnected()
{
qDebug() << "Disconnnected";
}
void qtozwdaemon::handleMessage(const QByteArray &message, const QMqttTopicName &topic) {
qDebug() << "Received: " << topic.name() << ":" << message;
}

View file

@ -3,6 +3,7 @@
#include <QObject>
#include <QString>
#include <QtMqtt/QMqttClient>
#include <qt-openzwave/qtopenzwave.h>
#include <qt-openzwave/qtozwmanager.h>
@ -22,12 +23,15 @@ signals:
public slots:
void QTOZW_Ready();
void updateLogStateChange();
void brokerDisconnected();
void handleMessage(const QByteArray &message, const QMqttTopicName &topic = QMqttTopicName());
private:
QTOpenZwave *m_openzwave;
QTOZWManager *m_qtozwmanager;
QString m_serialPort;
QMqttClient *m_client;
};
#endif // QTOZWDAEMON_H

0
updaterpath.sh Executable file → Normal file
View file