fix:空调数据下发、参数页样式
This commit is contained in:
@ -42,7 +42,6 @@ const createMqtt = () => {
|
||||
clean: true,
|
||||
reconnectPeriod: 1000, // 恢复自动重连,1秒重连一次
|
||||
connectTimeout: 5000, // 5s超时时间
|
||||
// topic: "HDYDCJ_01_DOWN",
|
||||
topic: "HDYDCJ_01_UP",
|
||||
rejectUnauthorized: false,
|
||||
// #ifdef MP-ALIPAY
|
||||
@ -245,11 +244,70 @@ const manualReconnect = () => {
|
||||
}, 300);
|
||||
};
|
||||
|
||||
// 发送MQTT数据(单独订阅HDYDCJ_01_DOWN)
|
||||
const sendMqttData = (data) => {
|
||||
try {
|
||||
if (!client || !client.connected) {
|
||||
console.error('❌ MQTT客户端未连接,无法发送数据');
|
||||
uni.showToast({
|
||||
title: 'MQTT未连接',
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
const message = JSON.stringify(data);
|
||||
console.log('📤 发送MQTT数据:', data);
|
||||
console.log('📤 发送消息内容:', message);
|
||||
console.log('📤 发送到主题: HDYDCJ_01_DOWN');
|
||||
|
||||
// 先订阅HDYDCJ_01_DOWN主题(如果还没有订阅)
|
||||
client.subscribe("HDYDCJ_01_DOWN", (err) => {
|
||||
if (err) {
|
||||
console.error('❌ 订阅HDYDCJ_01_DOWN失败:', err);
|
||||
} else {
|
||||
console.log('✅ 订阅HDYDCJ_01_DOWN成功');
|
||||
}
|
||||
});
|
||||
|
||||
// 发送数据到HDYDCJ_01_DOWN主题
|
||||
client.publish("HDYDCJ_01_DOWN", message, (err) => {
|
||||
if (err) {
|
||||
console.error('❌ MQTT数据发送失败:', err);
|
||||
uni.showToast({
|
||||
title: '数据发送失败',
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
});
|
||||
} else {
|
||||
console.log('✅ MQTT数据发送成功');
|
||||
uni.showToast({
|
||||
title: '数据发送成功',
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('❌ 发送MQTT数据异常:', error);
|
||||
uni.showToast({
|
||||
title: '发送数据异常',
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
createMqtt,
|
||||
closeMqtt,
|
||||
judgeBeat,
|
||||
getConnectionStatus,
|
||||
manualReconnect,
|
||||
sendMqttData,
|
||||
client,
|
||||
}
|
||||
Reference in New Issue
Block a user