Initial MQTT bell app based on systray

This commit is contained in:
2020-10-26 20:25:50 +01:00
commit 2debcf4c7d
27 changed files with 1926 additions and 0 deletions

50
subscriber.cpp Normal file
View File

@@ -0,0 +1,50 @@
#include "subscriber.h"
void Subscriber::onSettingsChanged(QHostAddress _host)
{
qDebug() << "Setting host:" << _host;
if (_host != host()) {
disconnect();
setHost(_host);
}
}
void Subscriber::onConnected()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope,"BAD Soft", "Bell");
settings.beginGroup("Subscriber");
qDebug() << "connected";
subscribe(settings.value("topic",EXAMPLE_TOPIC).toString(), 0);
settings.endGroup();
}
void Subscriber::onSubscribed(const QString& topic)
{
qDebug() << "subscribed " << topic;
}
void Subscriber::onReceived(const QMQTT::Message& message)
{
int bellNumber;
QString header;
QString msg;
qDebug() << "publish received: " << QString::fromUtf8(message.payload());
msg = QString::fromLatin1(message.payload());
QStringList list1 = msg.split(QLatin1Char(':'));
qDebug() << msg;
qDebug() << "List Size: " << list1.size();
if (list1.size() >= 2) {
header = list1.at(0);
qDebug() << "H: " << header;
if (header == "BELL") {
bellNumber = list1.at(1).toInt();
emit packetArrived(bellNumber);
}
}
}