set subscribed flag

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

View File

@@ -35,17 +35,18 @@ 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
for (auto const &localSub : mediator->subscriptions) if (!locallySubscribed)
{ {
// bind all local topics to the MQTT upstream once for (auto const &localSub : mediator->subscriptions)
if (!locallySubscribed)
{ {
// bind all local topics to the MQTT upstream once
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
client->subscribe(
(String(mqttConfig.inTopicRoot) + String(localSub.first.c_str()))
.c_str());
} }
// subscribe topic on remote queue to dispatch messages to local subscriptions locallySubscribed = true;
client->subscribe(
(String(mqttConfig.inTopicRoot) + String(localSub.first.c_str()))
.c_str());
} }
PRINT_MSG(Serial, "MQTT", "connected"); PRINT_MSG(Serial, "MQTT", "connected");
} }