-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmqtt.cpp
34 lines (29 loc) · 976 Bytes
/
mqtt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "mqtt.h"
#include <QJsonObject>
#include "Utils/config.h"
MQTTHandler::MQTTHandler(QObject *parent) : QObject(parent) {
QJsonObject config = Config::instance()->getConfig("mqtt");
topic = config.value("topic").toString();
client = new QMqttClient(this);
client->setHostname(config.value("host").toString());
client->setPort(config.value("port").toInt());
client->setUsername(config.value("user").toString());
client->setPassword(config.value("password").toString());
client->connectToHost();
}
void MQTTHandler::onWakeup() {
client->publish(topic + "wakeup");
}
void MQTTHandler::onDetect(bool stop) {
client->publish(topic + "detect");
}
void MQTTHandler::onASR(const QString& text, int id) {
if (id == 0) {
client->publish(topic + "question", text.toUtf8());
}
}
void MQTTHandler::onSay(const QString& text, int id) {
if (id == 0) {
client->publish(topic + "response", text.toUtf8());
}
}