Code Monkey home page Code Monkey logo

Comments (16)

pbpraha avatar pbpraha commented on July 27, 2024 1

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 :)

from vue-mqtt.

cuanjooste avatar cuanjooste commented on July 27, 2024

I have the same issue as above.

from vue-mqtt.

cuanjooste avatar cuanjooste commented on July 27, 2024

Thank you so much for this. Even though this is potentially a workaround, it does seem to add some additional flexibility. Thanks again!

from vue-mqtt.

nik-zp avatar nik-zp commented on July 27, 2024

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/[email protected]/Payment_Rsp" and "WebExtension/v1/[email protected]/BuyResult_Ind"

from vue-mqtt.

pbpraha avatar pbpraha commented on July 27, 2024

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.

from vue-mqtt.

nik-zp avatar nik-zp commented on July 27, 2024

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'
  }
}

from vue-mqtt.

pbpraha avatar pbpraha commented on July 27, 2024

hmm, i have other subs on this component too, they would also match, no?

from vue-mqtt.

nik-zp avatar nik-zp commented on July 27, 2024

All topics that match ''provisioning/key/confirm/#"

from vue-mqtt.

pbpraha avatar pbpraha commented on July 27, 2024

hmm, what if this ... ?

created () {
this.$mqtt.subscribe('provisioning/key/confirm/#')
this.$mqtt.subscribe('provisioning/something/something/#')
}
mqtt: {
allTopics (response) {...}
}

from vue-mqtt.

nik-zp avatar nik-zp commented on July 27, 2024

oh... I understood the problem. I'll think about it and write.

from vue-mqtt.

pbpraha avatar pbpraha commented on July 27, 2024

Cheers :)

from vue-mqtt.

nik-zp avatar nik-zp commented on July 27, 2024

Done. See example
https://github.com/nik-zp/Vue-Mqtt-Example

from vue-mqtt.

cuanjooste avatar cuanjooste commented on July 27, 2024

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!

from vue-mqtt.

nik-zp avatar nik-zp commented on July 27, 2024

@cuanjooste, hi.
see example for [email protected]:

mqtt: {
  'results/+/led' (data, topic) {
    if (topic.split('/')[1] === '1234') {
      // ...
    }
  }
}

from vue-mqtt.

cuanjooste avatar cuanjooste commented on July 27, 2024

@nik-zp That is perfect, thank you so much!!!!

from vue-mqtt.

pbpraha avatar pbpraha commented on July 27, 2024

Thanks also ! :)

I had to move off this project for now but will be sure to use this when i get back to it.

from vue-mqtt.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.