|
@ -7,13 +7,13 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
#include <QLoggingCategory>
|
|
|
#include <QStringList>
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
#include <QJsonDocument>
|
|
|
#include <QJsonObject>
|
|
|
#include <QJsonObject>
|
|
|
#include <QJsonValue>
|
|
|
#include <QJsonValue>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "mqttclient.h"
|
|
|
#include "mqttclient.h"
|
|
|
|
|
|
#include "settings.h"
|
|
|
#include "qmqtt.h"
|
|
|
#include "qmqtt.h"
|
|
|
|
|
|
|
|
|
MQTTSubcriber::MQTTSubcriber(const QHostAddress& host, const quint16 port, |
|
|
MQTTSubcriber::MQTTSubcriber(const QHostAddress& host, const quint16 port, |
|
@ -22,14 +22,6 @@ MQTTSubcriber::MQTTSubcriber(const QHostAddress& host, const quint16 port, |
|
|
connect(this, &MQTTSubcriber::connected, this, &MQTTSubcriber::onConnected); |
|
|
connect(this, &MQTTSubcriber::connected, this, &MQTTSubcriber::onConnected); |
|
|
connect(this, &MQTTSubcriber::subscribed, this, &MQTTSubcriber::onSubscribed); |
|
|
connect(this, &MQTTSubcriber::subscribed, this, &MQTTSubcriber::onSubscribed); |
|
|
connect(this, &MQTTSubcriber::received, this, &MQTTSubcriber::onReceived); |
|
|
connect(this, &MQTTSubcriber::received, this, &MQTTSubcriber::onReceived); |
|
|
m_sensor_topics << QString::fromUtf8("sensors/chambre_so/xiaomi"); |
|
|
|
|
|
m_sensor_topics << QString::fromUtf8("sensors/chambre_rico/xiaomi"); |
|
|
|
|
|
m_sensor_topics << QString::fromUtf8("sensors/salon/xiaomi"); |
|
|
|
|
|
m_sensor_topics << QString::fromUtf8("sensors/salle_de_bains/xiaomi"); |
|
|
|
|
|
m_availability_topics << QString::fromUtf8("sensors/chambre_so/availability"); |
|
|
|
|
|
m_availability_topics << QString::fromUtf8("sensors/chambre_rico/availability"); |
|
|
|
|
|
m_availability_topics << QString::fromUtf8("sensors/salon/availability"); |
|
|
|
|
|
m_availability_topics << QString::fromUtf8("sensors/salle_de_bains/availability"); |
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "created" << endl; |
|
|
qDebug() << "created" << endl; |
|
|
} |
|
|
} |
|
@ -55,8 +47,8 @@ void MQTTSubcriber::onReceived(const QMQTT::Message& message) |
|
|
qDebug() << "publish received: \"" << QString::fromUtf8(message.payload()) |
|
|
qDebug() << "publish received: \"" << QString::fromUtf8(message.payload()) |
|
|
<< "\"" << " from: " << message.topic() << endl; |
|
|
<< "\"" << " from: " << message.topic() << endl; |
|
|
|
|
|
|
|
|
for (int i = 0; i < m_sensor_topics.size(); ++i) { |
|
|
|
|
|
if (m_sensor_topics.at(i) == message.topic()) { |
|
|
|
|
|
|
|
|
for (int i = 0; i < Settings::getInstance()->m_sensor_topics.size(); ++i) { |
|
|
|
|
|
if (Settings::getInstance()->m_sensor_topics.at(i) == message.topic()) { |
|
|
qDebug() << "this is for us !" << endl; |
|
|
qDebug() << "this is for us !" << endl; |
|
|
sensorData = QJsonDocument::fromJson(message.payload()); |
|
|
sensorData = QJsonDocument::fromJson(message.payload()); |
|
|
if (!sensorData.isObject()) { |
|
|
if (!sensorData.isObject()) { |
|
|