Closed pbpraha closed 7 years ago
I have the same issue as above.
As a workaround (or is it the proper way?) I did this in my component mounted() method:
this.$mqtt.subscribe('param/param/param/#')
this.$mqtt.on('message', (topic, message) => { if (topic.match('param/param/param/')) { console.log('matched!') } })
Hope it helps :)
Thank you so much for this. Even though this is potentially a workaround, it does seem to add some additional flexibility. Thanks again!
Hi. I use so:
created () {
this.$mqtt.subscribe('WebExtension/v1/' + this.userProfile.email + '/#')
}
mqtt: {
Payment_Rsp (response) {
...
},
BuyResult_Ind (response) {
...
}
}
Full topic is "WebExtension/v1/none@none.com/Payment_Rsp" and "WebExtension/v1/none@none.com/BuyResult_Ind"
Hi,
Maybe i'm mis-using / misunderstanding mqtt topics.
I'm using topic === 'provisioning/key/confirm/123456' where '123456' is actually a variable.
that's why i can't use : mqtt: { [SOME_VARIABLE_NAME] (response) { ... }, ...
The variable name is not known ahead of time.
I'm building a handshaking / provisioning system so the '123456' is a keycode the user enters on a remote keypad and has to be passed around for a little while.
I can change to work like this:
created () {
this.$mqtt.subscribe('provisioning/key/confirm/#')
}
mqtt: {
allTopics (response) {
// for all topic,
// for example 'provisioning/key/confirm/123' | 'provisioning/key/confirm/456'
}
}
hmm, i have other subs on this component too, they would also match, no?
All topics that match ''provisioning/key/confirm/#"
hmm, what if this ... ?
created () {
this.$mqtt.subscribe('provisioning/key/confirm/#')
this.$mqtt.subscribe('provisioning/something/something/#')
}
mqtt: {
allTopics (response) {...}
}
oh... I understood the problem. I'll think about it and write.
Cheers :)
Done. See example https://github.com/nik-zp/Vue-Mqtt-Example
Thank you very much for this. I tested it and everything seems to be working fine. I am not sure if this will be a separate request or maybe just something to figure out in the future, but one advantage that this,$mqtt.on still has is that its possible to see the original topic.
An example to highlight this is Publish to : 'results/1/led' and 'results/2/led' Subscribe to : 'results/+/led/' MQTT function only has a parameter of val, so I am currently unable to distinguish between 1 & 2.
I understand this was not in the original request but just thought I would mention it. Thanks again for the quick work!
@cuanjooste, hi. see example for vue-mqtt@2.0.1:
mqtt: {
'results/+/led' (data, topic) {
if (topic.split('/')[1] === '1234') {
// ...
}
}
}
@nik-zp That is perfect, thank you so much!!!!
Thanks also ! :)
I had to move off this project for now but will be sure to use this when i get back to it.
Hi :)
Thanks for a great library :) Unfortunately, I'm unable to bind to + and # topics, subscribing works though.
this.$mqtt.subscribe('param/param/param/#') <- will subscribe
but...
mqtt: { 'param/param/param/#': function(val) { console.log('this method ...') }, },
does not log :(
i also tried : "param/param/param/" "param/param/param"
etc.
Can you advise please?
Thanks.