Merge branch 'liubiao-new-20250827'
This commit is contained in:
@ -6,6 +6,11 @@ const serviceDic = [ //合作供应商的蓝牙主服务
|
||||
"writeId": "0000FFE1-0000-1000-8000-00805F9B34FB",
|
||||
"notifyId": "0000FFE2-0000-1000-8000-00805F9B34FB"
|
||||
},
|
||||
{
|
||||
"serviceId": "0000FFF0-0000-1000-8000-00805F9B34FB",
|
||||
"writeId": "0000FFF2-0000-1000-8000-00805F9B34FB",
|
||||
"notifyId": "0000FFF1-0000-1000-8000-00805F9B34FB"
|
||||
},
|
||||
{
|
||||
"serviceId": "0000AE30-0000-1000-8000-00805F9B34FB",
|
||||
"writeId": "0000AE03-0000-1000-8000-00805F9B34FB",
|
||||
@ -510,7 +515,7 @@ class BleHelper {
|
||||
}
|
||||
|
||||
uni.onBluetoothAdapterStateChange((state) => {
|
||||
// console.log('蓝牙状态发生变化:' + JSON.stringify(state));
|
||||
console.log('蓝牙状态发生变化:' + JSON.stringify(state));
|
||||
this.data.discovering = state.discovering;
|
||||
|
||||
if (this.data.available !== state.available) {
|
||||
@ -632,18 +637,23 @@ class BleHelper {
|
||||
}, 0);
|
||||
});
|
||||
|
||||
console.log("111111111")
|
||||
uni.onBluetoothDeviceFound((res) => {
|
||||
// console.log("发现新设备:" + JSON.stringify(devices));
|
||||
// console.log("发现新设备:" + JSON.stringify(res,'name'));
|
||||
let arr = [];
|
||||
for (var i = 0; i < res.devices.length; i++) {
|
||||
let item = res.devices[i];
|
||||
// if(item.name){
|
||||
// console.log("发现新设备",item.name+" "+item.RSSI);
|
||||
// }
|
||||
|
||||
let f = serviceDic.find(v => {
|
||||
return item.advertisServiceUUIDs
|
||||
.includes(v.serviceId);
|
||||
});
|
||||
if (f) {
|
||||
|
||||
console.log("发现新设备:", item);
|
||||
// console.log("发现目标设备:", item);
|
||||
arr.push(item);
|
||||
}
|
||||
|
||||
@ -788,7 +798,7 @@ class BleHelper {
|
||||
if (isUpdate) {
|
||||
this.updateCache();
|
||||
}
|
||||
// console.log("str1=", str);
|
||||
// console.log("str1=", str);
|
||||
} catch (ex) {
|
||||
console.error("将数据转文本失败", ex);
|
||||
}
|
||||
@ -927,7 +937,7 @@ class BleHelper {
|
||||
services: serviceId ? [serviceId] : [],
|
||||
allowDuplicatesKey: true,
|
||||
success: (res) => {
|
||||
//console.log('开始搜索蓝牙设备成功');
|
||||
console.log('开始搜索蓝牙设备成功');
|
||||
resolve(res);
|
||||
|
||||
},
|
||||
@ -1198,7 +1208,7 @@ class BleHelper {
|
||||
deviceId: id,
|
||||
success: (res) => {
|
||||
if (res.services && res.services.length > 0) {
|
||||
// console.log("获取到服务:" + JSON.stringify(res));
|
||||
console.log("获取到服务:" + JSON.stringify(res));
|
||||
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == id) {
|
||||
@ -1223,7 +1233,7 @@ class BleHelper {
|
||||
});
|
||||
|
||||
if (se) {
|
||||
// console.log("合作供应商的", s)
|
||||
console.log("合作供应商的", s)
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == id) {
|
||||
v.writeServiceId = s.serviceId;
|
||||
@ -1241,7 +1251,9 @@ class BleHelper {
|
||||
// notifyCharId));
|
||||
|
||||
|
||||
} else {
|
||||
} else
|
||||
|
||||
{
|
||||
console.error("预设的蓝牙服务和特征中找不到");
|
||||
for (var i = 0; i < res.services.length; i++) {
|
||||
let service = res.services[i];
|
||||
@ -1261,6 +1273,7 @@ class BleHelper {
|
||||
|
||||
Promise.all(promises)
|
||||
.then(results => {
|
||||
console.log("results= ",results);
|
||||
if (!s) {
|
||||
//非指定供应商的设备,走订阅消息
|
||||
return this.subScribe(id, true);
|
||||
@ -1321,10 +1334,10 @@ class BleHelper {
|
||||
serviceId: serviceId,
|
||||
success: (res) => {
|
||||
|
||||
// console.log("获取到特征:" + JSON.stringify(res));
|
||||
// res.characteristics.forEach((v) => {
|
||||
// v.serviceId = serviceId;
|
||||
// });
|
||||
console.log("获取到特征:" + JSON.stringify(res));
|
||||
res.characteristics.forEach((v) => {
|
||||
v.serviceId = serviceId;
|
||||
});
|
||||
|
||||
//写特征
|
||||
let writeChar = res.characteristics.find(char => {
|
||||
@ -1467,7 +1480,7 @@ class BleHelper {
|
||||
deviceId: deviceId,
|
||||
timeout: 30000,
|
||||
success: (info) => {
|
||||
// console.log("新连接成功", this.data.LinkedList);
|
||||
console.log("新连接成功", this.data.LinkedList);
|
||||
this.getLinkBlue().then((arr) => {
|
||||
let cr = arr.devices.find(c => {
|
||||
if (c.deviceId == deviceId) {
|
||||
@ -1740,9 +1753,9 @@ class BleHelper {
|
||||
bufferHex = bytes.map(b => '0x' + b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
}
|
||||
}
|
||||
console.log("准备发送蓝牙指令 - deviceId:", deviceid, "writeServiceId:", writeServiceId, "writeCharactId:", wirteCharactId);
|
||||
console.log("发送数据(Hex):", bufferHex || "(空数据)");
|
||||
console.log("发送数据(原始buffer长度):", buffer ? (buffer.byteLength || buffer.length || 0) : 0);
|
||||
// console.log("准备发送蓝牙指令 - deviceId:", deviceid, "writeServiceId:", writeServiceId, "writeCharactId:", wirteCharactId);
|
||||
// console.log("发送数据(Hex):", bufferHex || "(空数据)");
|
||||
// console.log("发送数据(原始buffer长度):", buffer ? (buffer.byteLength || buffer.length || 0) : 0);
|
||||
if (ms === undefined) {
|
||||
ms = 50;
|
||||
}
|
||||
@ -1831,10 +1844,10 @@ class BleHelper {
|
||||
|
||||
}
|
||||
if (c.Linked) {
|
||||
console.log("蓝牙已连接,直接发送数据");
|
||||
// console.log("蓝牙已连接,直接发送数据");
|
||||
return sendBuffer();
|
||||
} else {
|
||||
console.log("蓝牙未连接,先连接蓝牙再发送数据");
|
||||
// console.log("蓝牙未连接,先连接蓝牙再发送数据");
|
||||
return new Promise((resolve, reject) => {
|
||||
let f = this.data.LinkedList.find((v) => {
|
||||
return v.deviceId == deviceid;
|
||||
@ -1888,6 +1901,7 @@ class BleHelper {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
let instance = null;
|
||||
|
||||
@ -7,7 +7,8 @@ class BleReceive {
|
||||
'/pages/650/HBY650': this.Receive_650.bind(this),
|
||||
'/pages/670/HBY670': this.Receive_670.bind(this),
|
||||
'/pages/4877/BJQ4877': this.Receive_4877.bind(this),
|
||||
'/pages/100/HBY100': this.Receive_100.bind(this)
|
||||
'/pages/100/HBY100': this.Receive_100.bind(this),
|
||||
'/pages/102/HBY102':this.Receive_102.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
@ -58,10 +59,10 @@ class BleReceive {
|
||||
|
||||
if (handler) {
|
||||
let data = handler(receive, f, path, recArr);
|
||||
console.log("handler返回的数据:", data);
|
||||
console.log("设备"+f.device.deviceName+"收到消息,handler返回的数据:", data);
|
||||
return data;
|
||||
} else {
|
||||
console.log("已收到消息,但无指定处理程序, deviceUrl:", f.device.detailPageUrl, "可用handlers:", keys);
|
||||
console.error("已收到消息,但无指定处理程序, deviceUrl:", f.device.detailPageUrl, "可用handlers:", keys);
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -536,7 +537,7 @@ class BleReceive {
|
||||
|
||||
try {
|
||||
|
||||
// console.log("str=",receive.str);
|
||||
console.log("str=",receive.str);
|
||||
receiveData = JSON.parse(receive.str);
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
@ -560,6 +561,44 @@ class BleReceive {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Receive_102(receive,f,path,recArr){
|
||||
let receiveData={};
|
||||
|
||||
try {
|
||||
|
||||
console.log("str=",receive.str);
|
||||
receiveData = JSON.parse(receive.str);
|
||||
|
||||
let recCnt = recArr.find(v => {
|
||||
return v.key.replace(/\//g, "").toLowerCase() == f.device.detailPageUrl
|
||||
.replace(/\//g, "").toLowerCase();
|
||||
});
|
||||
if (!recCnt) {
|
||||
if (receiveData.sta_PowerPercent<=20) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "设备电量低",
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
if (receiveData.sta_Intrusion===1) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "闯入报警中",
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
receiveData = {};
|
||||
console.log("文本解析失败",error)
|
||||
}
|
||||
return receiveData;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -393,4 +393,16 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
getOSAndUpload(){
|
||||
let os=uni.getSystemInfoSync().platform;
|
||||
let url=''
|
||||
if(os==='ios'){
|
||||
url='https://apps.apple.com/cn/app/星汉物联/id6752555460'
|
||||
}
|
||||
|
||||
else if(os==='android'){
|
||||
url='https://www.pgyer.com/xhwl';
|
||||
}
|
||||
return {os:os,url:url};
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import request, {
|
||||
baseURL
|
||||
} from '@/utils/request.js'
|
||||
|
||||
import Common from '@/utils/Common.js'
|
||||
/**
|
||||
* 检查并执行wgt热更新
|
||||
* @param {String} updateUrl - 检查更新的接口地址
|
||||
@ -178,10 +178,20 @@ function downloadAndInstallWgt(wgtUrl) {
|
||||
var wating = plus.nativeUI.showWaiting({
|
||||
title: "下载中0%"
|
||||
});
|
||||
// uni.showLoading({
|
||||
// title: '更新下载中...',
|
||||
// mask: true
|
||||
// });
|
||||
|
||||
//手动更新
|
||||
let ManualUpdate=()=>{
|
||||
setTimeout(()=>{
|
||||
|
||||
let url=Common.getOSAndUpload().url
|
||||
plus.runtime.openURL(url, (res) => {
|
||||
uni.showToast({
|
||||
title: '打开失败',
|
||||
icon: 'none'
|
||||
});
|
||||
});
|
||||
},1000);
|
||||
}
|
||||
|
||||
// 1. 下载wgt包
|
||||
const downloadTask = uni.downloadFile({
|
||||
@ -219,20 +229,22 @@ function downloadAndInstallWgt(wgtUrl) {
|
||||
|
||||
wating.close();
|
||||
uni.showToast({
|
||||
title: '安装失败: ' + error.message,
|
||||
title: '安装失败,请手动下载更新;' + error.message,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
console.error('wgt安装失败:', error);
|
||||
ManualUpdate();
|
||||
});
|
||||
|
||||
} else {
|
||||
wating.close();
|
||||
uni.showToast({
|
||||
title: '下载失败',
|
||||
title: '下载失败,请手动下载更新;',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
ManualUpdate();
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
@ -243,6 +255,7 @@ function downloadAndInstallWgt(wgtUrl) {
|
||||
duration: 2000
|
||||
});
|
||||
console.error('wgt下载失败:', err);
|
||||
ManualUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user