arcoirislabs / cordova-plugin-mqtt

MqTT Cordova Plugin for Apache Cordova (> v3.0)
MIT License
86 stars 49 forks source link

How to subscribe multiple topics ? #40

Open iotproductions opened 6 years ago

iotproductions commented 6 years ago

Hi, I'm looking for a way to subscribe multiple topics, can you please give some examples about it ? Thanks

arcoirislabs commented 6 years ago

Hi. You can use wildcard topic along with listen function to make a variable out of a pattern in wildcard

Sent from my 📲

On 08-Jun-2018, at 8:44 AM, IOT_Developer notifications@github.com wrote:

Hi, I'm looking for a way to subscribe multiple topics, can you please give some examples about it ? Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

iotproductions commented 6 years ago

Hi @arcoirislabs , Yes I know it, but on listen function i can not found any params which return Topic name. cordova.plugins.CordovaMqTTPlugin.listen("/topic/+singlewc/#multiwc",function(payload,params){ //Callback:- (If the user has published to /topic/room/hall) //payload : contains payload data //params : {singlewc:room,multiwc:hall} })

arcoirislabs commented 6 years ago

First subscribe to the topic using subscribe function. Then use listen function

Sent from my iPhone

On 08-Jun-2018, at 1:48 PM, IOT_Developer notifications@github.com wrote:

Hi @arcoirislabs , Yes I know it, but on listen function i can not found any params which return Topic name. cordova.plugins.CordovaMqTTPlugin.listen("/topic/+singlewc/#multiwc",function(payload,params){ //Callback:- (If the user has published to /topic/room/hall) //payload : contains payload data //params : {singlewc:room,multiwc:hall} })

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

iotproductions commented 6 years ago

Hi @arcoirislabs , I follow your sources and here is my SUBSCRIBE function:

//Simple subscribe cordova.plugins.CordovaMqTTPlugin.subscribe({ topic: "test_topic", qos: 1, success: function (s) { //New way to listen to topics cordova.plugins.CordovaMqTTPlugin.listen("test_topic", function (payload, params) { console.log("Received data: " + payload); }) }, error: function (e) { console.log("Something errors: " + e); } });

My function work fine but I'm looking for a way in order to Subscribe to any topic by user typed. It mean put dynamic topic into listen function. Could you please give me any suggestion to do it ? Thanks