设备控制

master
lld 2025-12-25 17:34:54 +08:00
parent 528caef3a5
commit a18f888531
1 changed files with 15 additions and 11 deletions

View File

@ -455,18 +455,20 @@ export default {
cancelText: '取消', cancelText: '取消',
confirmText: '确定', confirmText: '确定',
success: (res) =>{ success: (res) =>{
console.info("操作功能:【"+type+"】,变更状态为:"+ status) if (res.confirm) {
if (!this.connected) { console.info("操作功能:【"+type+"】,变更状态为:"+ status)
// mqtt if (!this.connected) {
this.connectMqtt() // 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) console.info(this.status)
@ -515,6 +517,7 @@ export default {
}, },
publishMessage() { publishMessage() {
console.info("开始发布消息")
if (!this.connected || !this.publishTopic || !this.message) { if (!this.connected || !this.publishTopic || !this.message) {
uni.showToast({ uni.showToast({
title: '控制设备失败', title: '控制设备失败',
@ -536,6 +539,7 @@ export default {
}, },
ackMessage(type) { ackMessage(type) {
console.info("处理回执消息")
this.client.on("message", (topic, payload) => { this.client.on("message", (topic, payload) => {
// 1. dtu/xxx/up // 1. dtu/xxx/up
if (topic !== this.status.subscribeTopic) return; if (topic !== this.status.subscribeTopic) return;