set subscribed flag

This commit is contained in:
2018-11-16 01:16:50 +01:00
parent 0a5bfc8cf9
commit cbba58095c

View File

@@ -35,18 +35,19 @@ void MqttPlugin::connect()
if (client->connect(mqttConfig.clientName)) if (client->connect(mqttConfig.clientName))
{ {
// bind handlers to all local subscriptions // bind handlers to all local subscriptions
if (!locallySubscribed)
{
for (auto const &localSub : mediator->subscriptions) for (auto const &localSub : mediator->subscriptions)
{ {
// bind all local topics to the MQTT upstream once // bind all local topics to the MQTT upstream once
if (!locallySubscribed)
{
subscribe(localSub.first.c_str(), bind(&MqttPlugin::upstreamHandler, this, localSub.first.c_str(), _1)); subscribe(localSub.first.c_str(), bind(&MqttPlugin::upstreamHandler, this, localSub.first.c_str(), _1));
}
// subscribe topic on remote queue to dispatch messages to local subscriptions // subscribe topic on remote queue to dispatch messages to local subscriptions
client->subscribe( client->subscribe(
(String(mqttConfig.inTopicRoot) + String(localSub.first.c_str())) (String(mqttConfig.inTopicRoot) + String(localSub.first.c_str()))
.c_str()); .c_str());
} }
locallySubscribed = true;
}
PRINT_MSG(Serial, "MQTT", "connected"); PRINT_MSG(Serial, "MQTT", "connected");
} }
} }