mirror of
https://gitlab.com/wirelos/sprocket-plugin-mqtt.git
synced 2025-12-14 05:46:49 +01:00
refactor for eventChannel
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user