documentation

This commit is contained in:
2018-11-15 13:12:02 +01:00
parent 99d72b06a0
commit 4f83ad4e0b
3 changed files with 31 additions and 23 deletions

View File

@@ -22,16 +22,11 @@ void MqttPlugin::enableConnectTask(Scheduler *scheduler)
void MqttPlugin::enableProcessTask(Scheduler *scheduler)
{
processTask.set(TASK_MILLISECOND * 5, TASK_FOREVER, bind(&MqttPlugin::process, this));
processTask.set(TASK_MILLISECOND * 5, TASK_FOREVER, bind(&PubSubClient::loop, client));
scheduler->addTask(processTask);
processTask.enable();
}
void MqttPlugin::process()
{
client->loop();
}
void MqttPlugin::connect()
{
if (!client->connected())
@@ -42,8 +37,11 @@ void MqttPlugin::connect()
// bind handlers to all local subscriptions
for (auto const &localSub : mediator->subscriptions)
{
// bind all local topics to the MQTT upstream
subscribe(localSub.first.c_str(), bind(&MqttPlugin::upstreamHandler, this, localSub.first.c_str(), _1));
// 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 topic on remote queue to dispatch messages to local subscriptions
client->subscribe(
(String(mqttConfig.inTopicRoot) + String(localSub.first.c_str()))
@@ -54,11 +52,6 @@ void MqttPlugin::connect()
}
}
void MqttPlugin::mqttPublish(String msg)
{
client->publish(mqttConfig.outTopicRoot, msg.c_str());
}
void MqttPlugin::upstreamHandler(String topic, String msg)
{
// publish message on remote queue