设备控制
parent
528caef3a5
commit
a18f888531
|
|
@ -455,18 +455,20 @@ export default {
|
|||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
success: (res) =>{
|
||||
console.info("操作功能:【"+type+"】,变更状态为:"+ status)
|
||||
if (!this.connected) {
|
||||
// 链接mqtt
|
||||
this.connectMqtt()
|
||||
if (res.confirm) {
|
||||
console.info("操作功能:【"+type+"】,变更状态为:"+ status)
|
||||
if (!this.connected) {
|
||||
// 链接mqtt
|
||||
this.connectMqtt()
|
||||
}
|
||||
// 组装消息
|
||||
this.message = JSON.stringify({[type]: status})
|
||||
console.info("指令:"+this.message)
|
||||
// 控制设备
|
||||
this.publishMessage();
|
||||
// 设备回执
|
||||
this.ackMessage(type);
|
||||
}
|
||||
// 组装消息
|
||||
this.message = JSON.stringify({[type]: status})
|
||||
console.info("指令:"+this.message)
|
||||
// 控制设备
|
||||
this.publishMessage();
|
||||
// 设备回执
|
||||
this.ackMessage(type);
|
||||
}
|
||||
})
|
||||
console.info(this.status)
|
||||
|
|
@ -515,6 +517,7 @@ export default {
|
|||
},
|
||||
|
||||
publishMessage() {
|
||||
console.info("开始发布消息")
|
||||
if (!this.connected || !this.publishTopic || !this.message) {
|
||||
uni.showToast({
|
||||
title: '控制设备失败',
|
||||
|
|
@ -536,6 +539,7 @@ export default {
|
|||
},
|
||||
|
||||
ackMessage(type) {
|
||||
console.info("处理回执消息")
|
||||
this.client.on("message", (topic, payload) => {
|
||||
// 1. 先判断是否是目标订阅主题(如dtu/xxx/up)
|
||||
if (topic !== this.status.subscribeTopic) return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue