|
|
@ -22,13 +22,19 @@ MQTTSubcriber::MQTTSubcriber(const QHostAddress& host, const quint16 port, |
|
|
|
connect(this, &MQTTSubcriber::connected, this, &MQTTSubcriber::onConnected); |
|
|
|
connect(this, &MQTTSubcriber::subscribed, this, &MQTTSubcriber::onSubscribed); |
|
|
|
connect(this, &MQTTSubcriber::received, this, &MQTTSubcriber::onReceived); |
|
|
|
|
|
|
|
connect(this, &MQTTSubcriber::published, this, &MQTTSubcriber::onPublished); |
|
|
|
connect(this, &MQTTSubcriber::error, this, &MQTTSubcriber::onError); |
|
|
|
qDebug() << "created" << endl; |
|
|
|
} |
|
|
|
|
|
|
|
MQTTSubcriber::~MQTTSubcriber() { |
|
|
|
} |
|
|
|
|
|
|
|
void MQTTSubcriber::onError(const QMQTT::ClientError error) |
|
|
|
{ |
|
|
|
qDebug() << "error" << error << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void MQTTSubcriber::onConnected() |
|
|
|
{ |
|
|
|
qDebug() << "connected" << endl; |
|
|
@ -88,4 +94,22 @@ out: |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void MQTTSubcriber::onPublished(const QMQTT::Message& message, quint16 msgid) |
|
|
|
{ |
|
|
|
qDebug() << "published" << msgid << " payload: " << message.topic() << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void MQTTSubcriber::onDisconnected(void) |
|
|
|
{ |
|
|
|
qDebug() << "disconnected" << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void MQTTSubcriber::publish_msg(const QString& topic, const QString& payload) |
|
|
|
{ |
|
|
|
// id is automatically incremented if ==0 and QoS>0
|
|
|
|
// DUP: if a message is resent, it should have the DUP flag
|
|
|
|
QMQTT::Message message(0, topic, payload.toUtf8(), 1, true, false); |
|
|
|
publish(message); |
|
|
|
} |
|
|
|
|
|
|
|
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ |