Fix mqtt items asserting on client instances
This commit is contained in:
parent
b0792d32db
commit
d69bfb58b9
4 changed files with 13 additions and 7 deletions
|
|
@ -47,7 +47,6 @@ void MqttSensorSource::onClientStateChanged(QMqttClient::ClientState state)
|
|||
{
|
||||
for(SensorSubscription& sensor : sensors)
|
||||
{
|
||||
qDebug()<<"MQTT subscribeing to"<<client->getBaseTopic() + "/" + sensor.topic;
|
||||
sensor.subscription = client->subscribe(client->getBaseTopic() + "/" + sensor.topic);
|
||||
connect(sensor.subscription->subscription, &QMqttSubscription::messageReceived, this, &MqttSensorSource::onMessageReceived);
|
||||
}
|
||||
|
|
@ -58,7 +57,7 @@ void MqttSensorSource::onClientStateChanged(QMqttClient::ClientState state)
|
|||
{
|
||||
if(sensor.subscription)
|
||||
{
|
||||
client->unsubscribe(sensor.topic);
|
||||
client->unsubscribe(client->getBaseTopic() + "/" + sensor.topic);
|
||||
sensor.subscription = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
@ -167,6 +166,6 @@ void MqttSensorSource::store(QJsonObject& json)
|
|||
MqttSensorSource::~MqttSensorSource()
|
||||
{
|
||||
for(SensorSubscription& sub : sensors)
|
||||
client->unsubscribe(sub.topic);
|
||||
client->unsubscribe(client->getBaseTopic() + "/" + sub.topic);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue