添加报警功能

This commit is contained in:
liub
2025-08-28 14:05:06 +08:00
parent c2aa8bfa2f
commit 9846fe2315
18 changed files with 1212 additions and 444 deletions

View File

@ -105,17 +105,17 @@ class BleHelper {
}
linkAllDevices() {
console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
for (var i = 0; i < this.data.LinkedList.length; i++) {
let device = this.data.LinkedList[i];
console.log("自动连接:" + device.deviceId);
// console.log("自动连接:" + device.deviceId);
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
.notifyCharactId);
}
} else {
console.log("无设备连接");
// console.log("无设备连接");
}
}
@ -128,7 +128,7 @@ class BleHelper {
}
const currentPage = pages[pages.length - 1];
console.log("currentPage=", currentPage.route);
// console.log("currentPage=", currentPage.route);
return currentPage.route;
}
@ -181,7 +181,7 @@ class BleHelper {
key = new Date().getTime();
}
if (key) {
console.log("订阅消息回调,key=" + key);
// console.log("订阅消息回调,key=" + key);
let f = this.cfg.receivDataCallback.findIndex((v) => {
return v.key == key;
});
@ -363,7 +363,7 @@ class BleHelper {
uni.openBluetoothAdapter({
success: (args) => {
console.log("蓝牙初始化成功:" + JSON.stringify(args));
// console.log("蓝牙初始化成功:" + JSON.stringify(args));
this.data.isOpenBlue = true;
this.data.available=true;
resolve(true);
@ -371,7 +371,7 @@ class BleHelper {
if (this.data.isSubscribe) { //整个App生命周期只订阅一次
return;
}
console.log("开始订阅各类变化消息");
// console.log("开始订阅各类变化消息");
this.data.isSubscribe = true;
@ -417,7 +417,7 @@ class BleHelper {
uni.setStorageSync(this.StorageKey, this.data
.LinkedList);
} else {
console.log("蓝牙连接已恢复,", res);
// console.log("蓝牙连接已恢复,", res);
}
});
@ -437,7 +437,7 @@ class BleHelper {
uni.onBLECharacteristicValueChange((receive) => {
//订阅消息
console.log("收到订阅消息",receive);
// console.log("收到订阅消息",receive);
let f=this.data.LinkedList.find((v) => {
return v.deviceId == receive.deviceId;
})
@ -500,7 +500,7 @@ class BleHelper {
str: str,
hexs: hexs
};
console.log("监听到特征值:" + JSON.stringify(recData));
// console.log("监听到特征值:" + JSON.stringify(recData));
if (this.cfg.receivDataCallback) {
if (this.cfg.receivDataCallback.length > 0) {
@ -678,7 +678,7 @@ class BleHelper {
state: state,
success: (res) => {
if (state) {
console.log("订阅消息成功", res);
// console.log("订阅消息成功", res);
} else {
console.log("取消订阅成功", res);
}

View File

@ -48,22 +48,23 @@ class BleReceive {
if(f && f.macAddress && f.id){
let data={};
if(f.detailPageUrl=='/pages/6155/deviceDetail'){
console.log("该设备是6155");
// console.log("该设备是6155");
data= this.Receive_6155(receive,f,path);
}
if(f.detailPageUrl=='/pages/650/HBY650'){
console.log("该设备是650");
// console.log("该设备是650");
data= this.Receive_650(receive,f,path);
}
if(f.detailPageUrl=='/pages/670/HBY670'){
console.log("该设备是670");
// console.log("该设备是670");
data= this.Receive_670(receive,f,path);
}
console.log("收到数据并处理完毕,",data);
// console.log("收到数据并处理完毕,",data);
return data;
}
console.log("已收到该消息,但无法处理",f);
// console.log("已收到该消息,但无法处理",receive);
return receive;
}
@ -253,11 +254,11 @@ class BleReceive {
Receive_670(receive,f,path){
var todo = (bytes) =>{
console.log("todo");
// console.log("todo",receive);
let receiveData = {};
if (bytes[0] == 0x55) {
try {
console.log("todo");
// console.log("todo");
// 跳过帧头(第一个字节),从第二个字节开始解析
let staticLevelByte = bytes[1];
let staticLevelText = '';
@ -275,7 +276,7 @@ class BleReceive {
staticLevelText = 'close';
break
}
console.log("todo");
// console.log("todo");
// 解析照明档位
let lightingLevelByte = bytes[2];
let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close';
@ -287,7 +288,7 @@ class BleReceive {
let batteryLevelByte = bytes[5];
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
console.log("todo");
// console.log("todo");
let warn = bytes[6];
if (warn == 0x00) {
warn = 'none';
@ -304,7 +305,7 @@ class BleReceive {
let staticWarn = bytes[7] == 0x01;//静止报警
let fourGStrenth = bytes[8]; //4g信号强度
let sosTxt = bytes[9] == 0x00 ? 'close' : bytes[9] == 0x01 ? 'sg' : 'rb';
console.log("todo");
// console.log("todo");
receiveData.modeCurr = staticLevelText;
receiveData.lightCurr = lightingLevelText;
receiveData.xuhang = lightingTime ;
@ -316,7 +317,7 @@ class BleReceive {
} catch(error) {
console.log('数据解析错误:', error);
}
console.log("todo");
// console.log("todo");
} else {
try {
let uint8Array = new Uint8Array(receive.value);
@ -340,6 +341,7 @@ class BleReceive {
console.log('收到纬度:', +this.receiveData.macAddress);
} else {
try {
// console.log("str=",str);
let json=JSON.parse(str);
if("staBlue_picture" in json){
//重发图片
@ -372,7 +374,7 @@ class BleReceive {
} catch (error) {
receiveData={};
console.log("文本解析失败")
// console.log("文本解析失败",error)
}
}
} catch(ex) {
@ -380,7 +382,7 @@ class BleReceive {
console.log('将数据转文本失败', ex);
}
}
console.log("todo",receiveData);
// console.log("todo",receiveData);
this.setBleFormData(receiveData,f);
return receiveData;
}

View File

@ -5,19 +5,17 @@ export const showLoading = (ev,options) => {
if(!ev){
return;
}
let defaultTxt="请稍候...";
if(!options){
options={a:1};
options={text:defaultTxt};
}
if(!options.text && options.title){
options.text=options.title;
}
if(!options.text){
options.text="请稍候...";
options.text=defaultTxt;
}
ev.$refs.loading.show(options);
}
// 隐藏loading

View File

@ -171,7 +171,7 @@ class MqttClient {
potentialJsons.forEach(jsonString => {
if (jsonString.trim() === '') return;
if (this.messageCallbacks.has(topic)) {
this.messageCallbacks.get(topic)(jsonString);
this.messageCallbacks.get(topic)(jsonString,message);
}
});
};
@ -285,8 +285,10 @@ class MqttClient {
mqttMessage.qos = 1;
this.client.send(mqttMessage);
console.log(`成功发布消息到主题 ${topic}: ${message}`);
return true;
} else {
console.error('MQTT未连接无法发布');
return false;
}
}

View File

@ -22,9 +22,11 @@ const request = (options) => {
header: options.header || {},
timeout: 30000,
success: (res) => {
console.log("res=",res);
resolve(res.data);
},
fail: (err) => {
console.log("ex=",err);
reject(err);
}
};