mirror of
https://github.com/Fishwaldo/qt-openzwave.git
synced 2025-03-15 19:41:24 +00:00
Basic MQTT Client working
This commit is contained in:
parent
05c28412b8
commit
fc98833c03
6 changed files with 46 additions and 3 deletions
0
makeosxbundle.sh
Executable file → Normal file
0
makeosxbundle.sh
Executable file → Normal file
|
@ -55,7 +55,7 @@ win32 {
|
||||||
} else {
|
} else {
|
||||||
equals(BUILDTYPE, "debug") {
|
equals(BUILDTYPE, "debug") {
|
||||||
exists ( $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL/OpenZWaved.dll )) {
|
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)
|
OZW_LIB_PATH = $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/ReleaseDLL)
|
||||||
} else {
|
} else {
|
||||||
error("Can't find a copy of OpenZWaved.dll in the DebugDLL Directory");
|
error("Can't find a copy of OpenZWaved.dll in the DebugDLL Directory");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
QT -= gui
|
QT -= gui
|
||||||
|
|
||||||
QT += remoteobjects
|
QT += remoteobjects mqtt
|
||||||
|
|
||||||
TARGET = ../ozwdaemon
|
TARGET = ../ozwdaemon
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,29 @@
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include "qtozwdaemon.h"
|
#include "qtozwdaemon.h"
|
||||||
|
|
||||||
|
|
||||||
qtozwdaemon::qtozwdaemon(QObject *parent) : QObject(parent)
|
qtozwdaemon::qtozwdaemon(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
this->m_openzwave = new QTOpenZwave(this);
|
this->m_openzwave = new QTOpenZwave(this);
|
||||||
this->m_qtozwmanager = this->m_openzwave->GetManager();
|
this->m_qtozwmanager = this->m_openzwave->GetManager();
|
||||||
QObject::connect(this->m_qtozwmanager, &QTOZWManager::ready, this, &qtozwdaemon::QTOZW_Ready);
|
QObject::connect(this->m_qtozwmanager, &QTOZWManager::ready, this, &qtozwdaemon::QTOZW_Ready);
|
||||||
this->m_qtozwmanager->initilizeSource(true);
|
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() {
|
void qtozwdaemon::QTOZW_Ready() {
|
||||||
|
@ -19,3 +36,25 @@ void qtozwdaemon::startOZW() {
|
||||||
}
|
}
|
||||||
//this->m_qtozwmanager->open(this->getSerialPort());
|
//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;
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QtMqtt/QMqttClient>
|
||||||
|
|
||||||
#include <qt-openzwave/qtopenzwave.h>
|
#include <qt-openzwave/qtopenzwave.h>
|
||||||
#include <qt-openzwave/qtozwmanager.h>
|
#include <qt-openzwave/qtozwmanager.h>
|
||||||
|
@ -22,12 +23,15 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void QTOZW_Ready();
|
void QTOZW_Ready();
|
||||||
|
void updateLogStateChange();
|
||||||
|
void brokerDisconnected();
|
||||||
|
void handleMessage(const QByteArray &message, const QMqttTopicName &topic = QMqttTopicName());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTOpenZwave *m_openzwave;
|
QTOpenZwave *m_openzwave;
|
||||||
QTOZWManager *m_qtozwmanager;
|
QTOZWManager *m_qtozwmanager;
|
||||||
QString m_serialPort;
|
QString m_serialPort;
|
||||||
|
QMqttClient *m_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QTOZWDAEMON_H
|
#endif // QTOZWDAEMON_H
|
||||||
|
|
0
updaterpath.sh
Executable file → Normal file
0
updaterpath.sh
Executable file → Normal file
Loading…
Add table
Reference in a new issue