Browse Source

add static settings

master
Richard Genoud 5 years ago
parent
commit
a9058190eb
7 changed files with 88 additions and 21 deletions
  1. +0
    -4
      soft/thermostat/inc/mqttclient.h
  2. +34
    -0
      soft/thermostat/inc/settings.h
  3. +1
    -6
      soft/thermostat/src/backgroundloop.cpp
  4. +1
    -0
      soft/thermostat/src/main.cpp
  5. +3
    -11
      soft/thermostat/src/mqttclient.cpp
  6. +47
    -0
      soft/thermostat/src/settings.cpp
  7. +2
    -0
      soft/thermostat/thermostat.pro

+ 0
- 4
soft/thermostat/inc/mqttclient.h View File

@ -10,7 +10,6 @@
#define MQTTCLIENT_H #define MQTTCLIENT_H
#include <QHostAddress> #include <QHostAddress>
#include <QStringList>
#include "qmqtt.h" #include "qmqtt.h"
@ -27,9 +26,6 @@ public slots:
void onConnected(); void onConnected();
void onSubscribed(const QString& topic); void onSubscribed(const QString& topic);
void onReceived(const QMQTT::Message& message); void onReceived(const QMQTT::Message& message);
private:
QStringList m_sensor_topics;
QStringList m_availability_topics;
}; };
#endif #endif


+ 34
- 0
soft/thermostat/inc/settings.h View File

@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2019 Richard Genoud
*
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QStringList>
class Settings
{
public:
static Settings *getInstance(void);
QStringList m_rooms_names;
QStringList m_sensor_topics;
QStringList m_availability_topics;
private:
Settings();
~Settings();
static Settings *_singleton;
};
#endif // SETTINGS_H
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

+ 1
- 6
soft/thermostat/src/backgroundloop.cpp View File

@ -7,19 +7,14 @@
*/ */
#include <QEventLoop> #include <QEventLoop>
#include <QDateTime>
#include <QElapsedTimer>
#include <QHostInfo>
#include <QHostAddress>
#include <QLoggingCategory> #include <QLoggingCategory>
#define LOOP_SLEEP_TIME_S 5
#include "backgroundloop.h" #include "backgroundloop.h"
BackgroundLoop::BackgroundLoop() { BackgroundLoop::BackgroundLoop() {
m_mqtt_client = NULL;
qsrand((uint)QDateTime::currentMSecsSinceEpoch());
} }
BackgroundLoop::~BackgroundLoop() { BackgroundLoop::~BackgroundLoop() {


+ 1
- 0
soft/thermostat/src/main.cpp View File

@ -11,6 +11,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QTranslator> #include <QTranslator>
#include "mqttclient.h"
#include "mainwindow.h" #include "mainwindow.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])


+ 3
- 11
soft/thermostat/src/mqttclient.cpp View File

@ -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()) {


+ 47
- 0
soft/thermostat/src/settings.cpp View File

@ -0,0 +1,47 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2019 Richard Genoud
*
*/
#include <QStringList>
#include <QString>
#include "settings.h"
Settings *Settings::_singleton = NULL;
Settings::Settings()
{
m_rooms_names << QString("Chambe So");
m_rooms_names << QString("Chambe Rico");
m_rooms_names << QString("Salon");
m_rooms_names << QString("Salle de bain");
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");
}
Settings::~Settings()
{
}
Settings *Settings::getInstance(void)
{
if (!_singleton) {
_singleton = new Settings;
}
return _singleton;
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */

+ 2
- 0
soft/thermostat/thermostat.pro View File

@ -25,12 +25,14 @@ SOURCES += src/main.cpp \
src/zoneitem.cpp \ src/zoneitem.cpp \
src/backgroundloop.cpp \ src/backgroundloop.cpp \
src/mqttclient.cpp \ src/mqttclient.cpp \
src/settings.cpp \
HEADERS += inc/mainwindow.h \ HEADERS += inc/mainwindow.h \
inc/zoneitem.h \ inc/zoneitem.h \
inc/backgroundloop.h \ inc/backgroundloop.h \
inc/mqttclient.h \ inc/mqttclient.h \
inc/settings.h \
RESOURCES += thermostat.qrc RESOURCES += thermostat.qrc


Loading…
Cancel
Save