添加102联机记录
This commit is contained in:
@ -281,7 +281,36 @@ class MqttClient {
|
||||
}
|
||||
}
|
||||
|
||||
publish(topic, message,retained) {
|
||||
async publish(topic, message,retained) {
|
||||
let getLan=()=>{
|
||||
return new Promise((succ,error)=>{
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
let networkType = res.networkType;
|
||||
// 判断网络是否连接
|
||||
if (networkType === 'none') {
|
||||
console.error('无网络连接')
|
||||
succ(false);
|
||||
} else {
|
||||
succ(true);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取网络状态失败:', err);
|
||||
|
||||
succ(false);
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
let flag=await getLan();
|
||||
if(!flag){
|
||||
|
||||
return false;
|
||||
}
|
||||
if (this.client && this.client.isConnected()) {
|
||||
const mqttMessage = new Paho.Message(message);
|
||||
mqttMessage.destinationName = topic;
|
||||
|
||||
Reference in New Issue
Block a user