From f326a7fed514a1a4767575143c16e8e330e6fc5c Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Wed, 18 Dec 2019 21:54:01 +0100 Subject: [PATCH] Thermostat: MQTTSubscriber->MQTTClient --- soft/thermostat/inc/mainwindow.h | 2 +- soft/thermostat/inc/mqttclient.h | 6 +++--- soft/thermostat/src/mainwindow.cpp | 2 +- soft/thermostat/src/mqttclient.cpp | 28 ++++++++++++++-------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/soft/thermostat/inc/mainwindow.h b/soft/thermostat/inc/mainwindow.h index 461115a..f3d883f 100644 --- a/soft/thermostat/inc/mainwindow.h +++ b/soft/thermostat/inc/mainwindow.h @@ -34,7 +34,7 @@ public: explicit MainWindow(QWidget *parent = NULL); ~MainWindow(); - MQTTSubcriber *mqttclient; + MQTTClient *mqttclient; private: QPushButton m_state_btn; diff --git a/soft/thermostat/inc/mqttclient.h b/soft/thermostat/inc/mqttclient.h index 98ce8f0..7390c93 100644 --- a/soft/thermostat/inc/mqttclient.h +++ b/soft/thermostat/inc/mqttclient.h @@ -14,14 +14,14 @@ #include "qmqtt.h" -class MQTTSubcriber: public QMQTT::Client +class MQTTClient: public QMQTT::Client { Q_OBJECT public: - explicit MQTTSubcriber(const QHostAddress& host = QHostAddress::LocalHost, + explicit MQTTClient(const QHostAddress& host = QHostAddress::LocalHost, const quint16 port = 1883, QObject* parent = NULL); - virtual ~MQTTSubcriber(); + virtual ~MQTTClient(); void publish_msg(const QString& topic, const QString& payload); private: diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index a9a88dd..6a67631 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent) : Settings *s = Settings::getInstance(); - mqttclient = new MQTTSubcriber(QHostAddress(s->m_broker.address), s->m_broker.port); + mqttclient = new MQTTClient(QHostAddress(s->m_broker.address), s->m_broker.port); for (int i = 0; i < s->nbZones(); i++) { zone = new ZoneItem(s->m_rooms.at(i).name, this); diff --git a/soft/thermostat/src/mqttclient.cpp b/soft/thermostat/src/mqttclient.cpp index e513af2..c3c787f 100644 --- a/soft/thermostat/src/mqttclient.cpp +++ b/soft/thermostat/src/mqttclient.cpp @@ -16,37 +16,37 @@ #include "settings.h" #include "qmqtt.h" -MQTTSubcriber::MQTTSubcriber(const QHostAddress& host, const quint16 port, +MQTTClient::MQTTClient(const QHostAddress& host, const quint16 port, QObject* parent) : QMQTT::Client(host, port, parent) { - connect(this, &MQTTSubcriber::connected, this, &MQTTSubcriber::onConnected); - connect(this, &MQTTSubcriber::subscribed, this, &MQTTSubcriber::onSubscribed); - connect(this, &MQTTSubcriber::received, this, &MQTTSubcriber::onReceived); - connect(this, &MQTTSubcriber::published, this, &MQTTSubcriber::onPublished); - connect(this, &MQTTSubcriber::error, this, &MQTTSubcriber::onError); + connect(this, &MQTTClient::connected, this, &MQTTClient::onConnected); + connect(this, &MQTTClient::subscribed, this, &MQTTClient::onSubscribed); + connect(this, &MQTTClient::received, this, &MQTTClient::onReceived); + connect(this, &MQTTClient::published, this, &MQTTClient::onPublished); + connect(this, &MQTTClient::error, this, &MQTTClient::onError); qDebug() << "created" << endl; } -MQTTSubcriber::~MQTTSubcriber() { +MQTTClient::~MQTTClient() { } -void MQTTSubcriber::onError(const QMQTT::ClientError error) +void MQTTClient::onError(const QMQTT::ClientError error) { qDebug() << "error" << error << endl; } -void MQTTSubcriber::onConnected() +void MQTTClient::onConnected() { qDebug() << "connected" << endl; this->subscribe("sensors/#", 1); } -void MQTTSubcriber::onSubscribed(const QString& topic) +void MQTTClient::onSubscribed(const QString& topic) { qDebug() << "subscribed " << topic << endl; } -void MQTTSubcriber::onReceived(const QMQTT::Message& message) +void MQTTClient::onReceived(const QMQTT::Message& message) { Settings *s = Settings::getInstance(); QJsonDocument sensorData; @@ -94,17 +94,17 @@ out: return; } -void MQTTSubcriber::onPublished(const QMQTT::Message& message, quint16 msgid) +void MQTTClient::onPublished(const QMQTT::Message& message, quint16 msgid) { qDebug() << "published" << msgid << " payload: " << message.topic() << endl; } -void MQTTSubcriber::onDisconnected(void) +void MQTTClient::onDisconnected(void) { qDebug() << "disconnected" << endl; } -void MQTTSubcriber::publish_msg(const QString& topic, const QString& payload) +void MQTTClient::publish_msg(const QString& topic, const QString& payload) { // id is automatically incremented if ==0 and QoS>0 // DUP: if a message is resent, it should have the DUP flag