From 2145002f3470e0ba27a1a4a447271c75c16533d3 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Wed, 18 Dec 2019 09:11:31 +0100 Subject: [PATCH] Thermostat: add broker infos in settings --- soft/thermostat/Thermostat.conf | 4 ++++ soft/thermostat/inc/settings.h | 6 ++++++ soft/thermostat/src/mainwindow.cpp | 2 +- soft/thermostat/src/settings.cpp | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/soft/thermostat/Thermostat.conf b/soft/thermostat/Thermostat.conf index 5c15ae5..1fbf6f3 100644 --- a/soft/thermostat/Thermostat.conf +++ b/soft/thermostat/Thermostat.conf @@ -1,6 +1,10 @@ # This file should be in: # $HOME/.config/Sorico/Thermostat.conf +[broker] +address=192.168.1.2 +port=1883 + [rooms] 1\heaters\1\control_topic=chauffage/chambre_so 1\heaters\size=1 diff --git a/soft/thermostat/inc/settings.h b/soft/thermostat/inc/settings.h index e92de8e..a96e730 100644 --- a/soft/thermostat/inc/settings.h +++ b/soft/thermostat/inc/settings.h @@ -25,6 +25,11 @@ struct Room { QVector heaters; }; +struct Brocker { + QString address; + int port; +}; + class Settings : public QSettings { Q_OBJECT @@ -33,6 +38,7 @@ public: int nbZones(); QVector m_rooms; + struct Brocker m_broker; private: Settings(); diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index 9de20f0..d314d55 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("192.168.1.2"), 1883); + mqttclient = new MQTTSubcriber(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/settings.cpp b/soft/thermostat/src/settings.cpp index 45d2e66..0935298 100644 --- a/soft/thermostat/src/settings.cpp +++ b/soft/thermostat/src/settings.cpp @@ -41,6 +41,8 @@ Settings::Settings() m_rooms << room; } s.endArray(); + m_broker.address = s.value("broker/address", "localhost").toString(); + m_broker.port = s.value("broker/port", 1883).toInt(); } int Settings::nbZones(void)