|
|
@@ -12,29 +12,23 @@ export function initMqtt(app: App<Element>) {
|
|
|
}
|
|
|
const client = mqtt.connect('ws://1.15.92.205:8083/mqtt', options)
|
|
|
client.on('connect', () => {
|
|
|
- client.subscribe('topic/goaf/waring/person', (err: any) => {
|
|
|
+ client.subscribe('topic/#', (err: any) => {
|
|
|
if (!err) {
|
|
|
- client.publish('topic/goaf/waring/person', 'Hello mqtt')
|
|
|
+ client.publish('topic1', 'sub failed')
|
|
|
}
|
|
|
else {
|
|
|
- client.publish('topic/goaf/waring/person', 'Hello mqtt err')
|
|
|
- }
|
|
|
- })
|
|
|
- client.subscribe('topic/goaf/waring/sensor', (err: any) => {
|
|
|
- if (!err) {
|
|
|
- client.publish('topic/goaf/waring/sensor', 'Hello mqtt')
|
|
|
- }
|
|
|
- else {
|
|
|
- client.publish('topic/goaf/waring/sensor', 'Hello mqtt err')
|
|
|
+ client.publish('topic2', 'sub succesed!')
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
client.on('message', (topic: any, message: any) => {
|
|
|
- const messageInfo = {
|
|
|
- message,
|
|
|
- time: new Date().getTime(),
|
|
|
+ if (topic) {
|
|
|
+ const messageInfo = {
|
|
|
+ message,
|
|
|
+ time: new Date().getTime(),
|
|
|
+ }
|
|
|
+ mqttStore.setMqttMessage(topic, messageInfo)
|
|
|
}
|
|
|
- mqttStore.setMqttMessage(topic, messageInfo)
|
|
|
})
|
|
|
if (app) {
|
|
|
app.config.globalProperties.$mqtt = client
|
|
|
@@ -45,7 +39,7 @@ export function mqttWatch(topic: string | number, callback: (arg0: any) => void)
|
|
|
if (!topic) {
|
|
|
return
|
|
|
}
|
|
|
- watch(() => mqttStore.message.value[topic], (val) => {
|
|
|
+ watch(() => mqttStore.message, (val) => {
|
|
|
callback(val)
|
|
|
})
|
|
|
}
|