|
@ -16,37 +16,37 @@ |
|
|
#include "settings.h"
|
|
|
#include "settings.h"
|
|
|
#include "qmqtt.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) |
|
|
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; |
|
|
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; |
|
|
qDebug() << "error" << error << endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void MQTTSubcriber::onConnected() |
|
|
|
|
|
|
|
|
void MQTTClient::onConnected() |
|
|
{ |
|
|
{ |
|
|
qDebug() << "connected" << endl; |
|
|
qDebug() << "connected" << endl; |
|
|
this->subscribe("sensors/#", 1); |
|
|
this->subscribe("sensors/#", 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void MQTTSubcriber::onSubscribed(const QString& topic) |
|
|
|
|
|
|
|
|
void MQTTClient::onSubscribed(const QString& topic) |
|
|
{ |
|
|
{ |
|
|
qDebug() << "subscribed " << topic << endl; |
|
|
qDebug() << "subscribed " << topic << endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void MQTTSubcriber::onReceived(const QMQTT::Message& message) |
|
|
|
|
|
|
|
|
void MQTTClient::onReceived(const QMQTT::Message& message) |
|
|
{ |
|
|
{ |
|
|
Settings *s = Settings::getInstance(); |
|
|
Settings *s = Settings::getInstance(); |
|
|
QJsonDocument sensorData; |
|
|
QJsonDocument sensorData; |
|
@ -94,17 +94,17 @@ out: |
|
|
return; |
|
|
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; |
|
|
qDebug() << "published" << msgid << " payload: " << message.topic() << endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void MQTTSubcriber::onDisconnected(void) |
|
|
|
|
|
|
|
|
void MQTTClient::onDisconnected(void) |
|
|
{ |
|
|
{ |
|
|
qDebug() << "disconnected" << endl; |
|
|
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
|
|
|
// id is automatically incremented if ==0 and QoS>0
|
|
|
// DUP: if a message is resent, it should have the DUP flag
|
|
|
// DUP: if a message is resent, it should have the DUP flag
|
|
|