From 7363e03b7403a6203796f9867c7a90b998d581e1 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Fri, 28 Dec 2018 20:25:19 +0100 Subject: [PATCH] refactor for eventChannel --- src/MqttPlugin.cpp | 2 +- src/MqttPlugin.h | 2 +- src/examples/chat/main.cpp | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/MqttPlugin.cpp b/src/MqttPlugin.cpp index 3a926a6..936288a 100644 --- a/src/MqttPlugin.cpp +++ b/src/MqttPlugin.cpp @@ -56,7 +56,7 @@ void MqttPlugin::connect() // bind handlers to all local subscriptions if (!subscribed) { - for (auto const &localSub : mediator->subscriptions) + for (auto const &localSub : eventChannel->subscriptions) { if(bindUpstream){ // bind all local topics to the MQTT upstream once diff --git a/src/MqttPlugin.h b/src/MqttPlugin.h index b2fbcbc..4299977 100644 --- a/src/MqttPlugin.h +++ b/src/MqttPlugin.h @@ -45,7 +45,7 @@ private: void enableConnectTask(Scheduler *scheduler); void enableProcessTask(Scheduler *scheduler); /** - * Connects to MQTT server and subscribes all topics available in the mediator + * Connects to MQTT server and subscribes all topics available in the eventChannel * to the corresponding topic on the remote queue by prefixing the topic with inRootTopic. * Creates shadow subscriptions of every local topic to propagate messages to the remote queue via upstreamHandler. */ diff --git a/src/examples/chat/main.cpp b/src/examples/chat/main.cpp index 0ebbbd1..cfeadf2 100644 --- a/src/examples/chat/main.cpp +++ b/src/examples/chat/main.cpp @@ -3,6 +3,10 @@ #include "Sprocket.h" #include "MqttPlugin.h" +const char* mqChatTopic = "wirelos/chat/log"; +const char* outChatTopic = "out/chat/log"; +const char* chatUser = "user"; + WiFiNet *network; Sprocket *sprocket; MqttPlugin *mqttPlugin; @@ -27,7 +31,7 @@ void setup() // PRINT_MSG(Serial, "CHAT", msg.c_str()); //}); publishHeap.set(TASK_SECOND * 5, TASK_FOREVER, []() { - sprocket->publish("out/chat/log", "hi there"); + sprocket->publish(outChatTopic, "hi there"); }); sprocket->addTask(publishHeap); @@ -41,11 +45,7 @@ void setup() CONNECT_TIMEOUT); network->connect(); - const char* mqChatTopic = "wirelos/chat/log"; - const char* outChatTopic = "out/chat/log"; - const char* chatUser = "user"; - - sprocket->subscribe("mqtt/connect", [mqChatTopic, outChatTopic, chatUser](String msg) { + sprocket->subscribe("mqtt/connect", [](String msg) { if (msg.length() > 0) { mqttPlugin->client->subscribe(mqChatTopic); @@ -55,7 +55,7 @@ void setup() }); // send message from WS to this topic - sprocket->subscribe(outChatTopic, [mqChatTopic, chatUser](String msg) { + sprocket->subscribe(outChatTopic, [](String msg) { PRINT_MSG(Serial, "CHAT", msg.c_str()); mqttPlugin->client->publish(mqChatTopic, (String(chatUser) + ": " + msg).c_str()); });