Reputation: 554
How can I do subscription to multiple topics and log content on receive ?
function subscribe()
{
var topic = "Device/MainTopic1/";
var topic1 = "Device/MainTopic2/";
var qos = "0";
client.subscribe([(topic, {qos: Number(qos)}), (topic1, {qos: Number(qos)})]); // Not working
client.subscribe(topic,{qos: Number(qos)}); // Single topic Working - Could only invoke once
}
Currently based on my current research found this issue logged in git. Any pointers would help. https://github.com/eclipse/paho.mqtt.javascript/issues/16
Upvotes: 2
Views: 4555
Reputation: 59638
As mentioned in the comment on that git issue you can just call subscribe
multiple times with each topic you need. There is no single call to subscribe to multiple topics in the Javascript client at this time.
function subscribe()
{
var topic = "Device/MainTopic1";
var topic1 = "Device/MainTopic2";
var qos = 0;
client.subscribe(topic,{qos: qos});
client.subscribe(topoic1,{qos:qos});
}
This should work just fine.
Also topics should not have trailing or leading '/' chars, they add null elements to the topic tree that make them harder wild card properly
Upvotes: 3