1
0
forked from dyf/APP

修改App图标、名称、蓝牙加入断线重连

This commit is contained in:
liub
2025-09-16 11:37:06 +08:00
parent 52b3bd796c
commit 778594574b
14 changed files with 3589 additions and 3686 deletions

40
App.vue
View File

@ -6,26 +6,26 @@
onLaunch: function() {
//以下代码仅在开发时使用,否则会出现不可预知的问题。
//清除登陆之外的所有信息;
let store=uni.getStorageInfoSync();
store.keys.forEach((val,index,array)=>{
if(val=="tokenTime"){
let time=uni.getStorageSync(val);
if(!time){
time=0;
}
let currTime=new Date().getTime();
if(currTime>=time){
uni.removeStorageSync(val);
uni.removeStorageSync("token");
uni.removeStorageSync("clientID");
}
}
else if(val=="token" || val=="clientID"){
console.log("忽略登陆信息");
}else{
uni.removeStorageSync(val);
}
});
// let store=uni.getStorageInfoSync();
// store.keys.forEach((val,index,array)=>{
// if(val=="tokenTime"){
// let time=uni.getStorageSync(val);
// if(!time){
// time=0;
// }
// let currTime=new Date().getTime();
// if(currTime>=time){
// uni.removeStorageSync(val);
// uni.removeStorageSync("token");
// uni.removeStorageSync("clientID");
// }
// }
// else if(val=="token" || val=="clientID"){
// console.log("忽略登陆信息");
// }else{
// uni.removeStorageSync(val);
// }
// });
//以上代码仅在开发时使用,否则会出现不可预知的问题。
uni.getSystemInfo({success:function(res){

View File

@ -2,7 +2,7 @@
const config = {
// 开发环境
development: {
BASE_URL: 'http://192.168.110.54:8000',
BASE_URL: 'http://192.168.110.56:8000',
API_PREFIX: '',
// MQTT 配置
MQTT_HOST: '47.120.79.150',

View File

@ -1,5 +1,5 @@
{
"name" : "JingQuan",
"name" : "星汉物联",
"appid" : "__UNI__A21EF43",
"description" : "设备管控",
"versionName" : "1.0.24",
@ -21,7 +21,6 @@
"Bluetooth" : {},
"Barcode" : {},
"Camera" : {},
"Maps" : {},
"OAuth" : {},
"Geolocation" : {}
},

View File

@ -1,12 +1,12 @@
{
"pages": [
// {
// "path": "pages/BlueTooth/ModeSetting/index",
// "style": {
// "navigationBarTitleText": "设备类型"
// }
// },
{
"path": "pages/BlueTooth/ModeSetting/index",
"style": {
"navigationBarTitleText": "设备类型"
}
},
{
"path": "pages/common/login/index",
"style": {

View File

@ -151,6 +151,11 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import {
registerPersonInfo
} from '@/api/6170/deviceControl.js';
var ble = null;
var these = null;
var BrighInteval = null;
@ -228,7 +233,26 @@
textLines: ['', '', ''],
mode: ''
},
inteval: 200
inteval: 200,
device: {
id: "",
deviceName: "",
deviceImei: "",
deviceMac: "",
communicationMode: 0,
devicePic: "",
typeName: "",
bluetoothName: null,
deviceStatus: null,
bindingTime: "",
onlineStatus: 0,
battery: "0",
latitude: null,
longitude: null,
alarmStatus: null,
detailPageUrl: "/pages/6155/deviceDetail",
showConfirm: false
}
}
},
@ -290,9 +314,10 @@
let device = data.data;
these.device = device;
console.log("收到父页面的参数:" + JSON.stringify(device));
let f = ble.data.LinkedList.find((v) => {
if (v.deviceId == device.deviceId) {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
@ -362,7 +387,7 @@
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
return v.macAddress == these.device.deviceMac;
});
return f;
@ -432,7 +457,7 @@
this.formData.statu = warn;
this.formData.xuhang = lightingTime;
if(batteryLevel<=20){
if (batteryLevel <= 20) {
this.showPop({
message: "设备电量低",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
@ -495,12 +520,12 @@
var list = [];
let index = 0; // 用于追踪arr的当前位置
let packetSize=2048;
let cSize=248;
let packetSize = 2048;
let cSize = 248;
// 外层循环7个主要元素i从1到7
for (let i = 1; i < 8; i++) {
let secondLevel = [];
let secondCnt=0;
let secondCnt = 0;
// 中层循环每个主要元素包含9个子数组j从1到9
for (let j = 1; j < 10; j++) {
// 确定当前子数组的长度前8个是254第9个是64
@ -510,7 +535,7 @@
// 从arr中提取相应数量的元素
for (let k = 0; k < cSize && index < arr.length; k++) {
if(secondCnt==packetSize){
if (secondCnt == packetSize) {
break;
}
thirdLevel.push(arr[index]);
@ -523,17 +548,17 @@
list.push(secondLevel);
}
console.log("list=",list);
console.log("list=", list);
let length=0;
let length = 0;
for (let i = 0; i < list.length; i++) {
const item = list[i];
let clength=0;
let clength = 0;
for (let j = 0; j < item.length; j++) {
const element = item[j];
console.log("第"+i+"包,第"+j+"小包,长度:"+element.length)
length+=element.length;
clength+=element.length;
console.log("第" + i + "包,第" + j + "小包,长度:" + element.length)
length += element.length;
clength += element.length;
}
@ -558,17 +583,19 @@
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
setTimeout(()=>{
setTimeout(() => {
hideLoading(these);
these.Status.BottomMenu.show = false;
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
});
resolve();
},20000)
}, 20000)
return;
}
@ -586,31 +613,30 @@
// resolve();
// return;
// }
let start=0;
let bufferSize=packetData.length*2;
let start = 0;
let bufferSize = packetData.length * 2;
if(currentPacket==7 ){
if(childPacket>2 && childPacket<9){
bufferSize=496;
}
else if(childPacket==9){
bufferSize=128;
if (currentPacket == 7) {
if (childPacket > 2 && childPacket < 9) {
bufferSize = 496;
} else if (childPacket == 9) {
bufferSize = 128;
}
}
if(childPacket==1){
bufferSize=bufferSize+8
start=8;
if (childPacket == 1) {
bufferSize = bufferSize + 8
start = 8;
}
if(childPacket==9 ){//|| (currentPacket==7 && childPacket==3
bufferSize=bufferSize+1
if (childPacket == 9) { //|| (currentPacket==7 && childPacket==3
bufferSize = bufferSize + 1
}
//FA 09 10 04 FC 09 [00] [01] + 4096字节+FF 数据格式
var buffer = new ArrayBuffer(bufferSize);
var dataView = new DataView(buffer);
if(childPacket==1){
if (childPacket == 1) {
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x09); // 帧头
dataView.setUint8(2, 0x10); // 帧头
@ -625,10 +651,10 @@
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
}
console.log("packetData.length=",packetData.length);
console.log("bufferSize=",bufferSize)
if(childPacket==9){// || (currentPacket==7 && childPacket==3
dataView.setUint8(bufferSize-1, 0xFF);
console.log("packetData.length=", packetData.length);
console.log("bufferSize=", bufferSize)
if (childPacket == 9) { // || (currentPacket==7 && childPacket==3
dataView.setUint8(bufferSize - 1, 0xFF);
}
//发送数据包
@ -638,7 +664,8 @@
let curr = childPacket + (currentPacket - 1) *
totalChildPacket;
console.log(""+currentPacket+"大包,"+childPacket+"小包发送完成,总计"+curr);
console.log("第" + currentPacket + "大包,第" + childPacket +
"小包发送完成,总计:" + curr);
updateLoading(these, {
text: "正在发送" + curr + "/63"
@ -994,7 +1021,7 @@
dataView.setUint8(bufferSize - 1, 0xFF);
let inteval =parseInt(this.inteval ? this.inteval : 50);
let inteval = parseInt(this.inteval ? this.inteval : 50);
console.log("inteval=", inteval)
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 30).then(() => {
@ -1027,12 +1054,12 @@
console.log("11111");
var result = null;
try {
console.log("this.$refs.textToHex=",this.$refs.textToHex);
console.log("this.$refs.textToHex=", this.$refs.textToHex);
result = await this.$refs.textToHex.drawAndGetPixels();
} catch (ex) {
console.log("ex=", ex);
}
if(!result){
if (!result) {
hideLoading(this);
return;
}
@ -1086,8 +1113,26 @@ if(!result){
if (flag) {
console.log("发送成功");
this.showPop({
message: "发送成功"
message: "发送成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
});
// let formdata = {
// code:"",
// name: these.formData.textLines[2],
// position: these.formData.textLines[1],
// unitName: these.formData.textLines[0],
// deviceId: these.device.id,
// deviceImei: these.device.deviceImei
// };
// registerPersonInfo(formdata).then(res=>{
// console.log("res=",res);
// }).catch(ex=>{
// console.log("ex=",ex);
// });
} else {
this.showPop({
message: "出现异常发送失败",

View File

@ -173,6 +173,11 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import {request,baseURL} from '../../utils/request';
import {
registerPersonInfo
} from '@/api/6170/deviceControl.js';
const pagePath = "pages/650/HBY650";
var ble = null;
var these = null;
@ -259,7 +264,26 @@
iswarn: false
},
rgb565Data: [],
videoHexArray: []
videoHexArray: [],
device: {
id: "",
deviceName: "",
deviceImei: "",
deviceMac: "",
communicationMode: 0,
devicePic: "",
typeName: "",
bluetoothName: null,
deviceStatus: null,
bindingTime: "",
onlineStatus: 0,
battery: "0",
latitude: null,
longitude: null,
alarmStatus: null,
detailPageUrl: "/pages/650/HBY650",
showConfirm: false
},
}
},
@ -278,7 +302,7 @@
console.log("收到父页面的参数:" + JSON.stringify(data));
var device = data.data;
these.device=device;
let f = ble.data.LinkedList.find((v) => {
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
@ -374,9 +398,9 @@
return className;
},
bleValueNotify: function(receive, device, path) { //订阅消息
console.log("收到设备的数据", data)
let data = recei.ReceiveData(receive, device, pagePath);
console.log("收到设备的数据",data)
if (data) {
if ("staBlue_picture" in data) {
//重发图片
@ -403,7 +427,7 @@ console.log("收到设备的数据",data)
let keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if(key in these.formData){
if (key in these.formData) {
these.formData[key] = data[key];
}
@ -434,7 +458,7 @@ console.log("收到设备的数据",data)
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
return v.macAddress == these.device.deviceMac;
});
return f;
@ -606,10 +630,11 @@ console.log("收到设备的数据",data)
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
});
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f
setTimeout(() => {
these.HoldYouHand("transmit complete", 0, f
.deviceId, f
.writeServiceId, f.wirteCharactId);
},500);
}, 500);
}
@ -635,7 +660,7 @@ console.log("收到设备的数据",data)
const packetData = these.rgb565Data.slice(startIndex,
endIndex);
// 构建数据包
const bufferSize =505;// 5 + packetData.length * 2; // 头部5字节 + 数据部分
const bufferSize = 505; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
@ -774,14 +799,16 @@ console.log("收到设备的数据",data)
console.log("准备发送一段数据");
if (currentPacket > totalPackets) {
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f
.writeServiceId, f.wirteCharactId).then(()=>{
setTimeout(() => {
these.HoldYouHand("transmit complete", 0, f
.deviceId, f
.writeServiceId, f.wirteCharactId).then(
() => {
console.log("全部发送完毕")
}).catch((ex)=>{
console.log("出现异常",ex);
}).catch((ex) => {
console.log("出现异常", ex);
});
},500);
}, 500);
}
these.Status.BottomMenu.show = false;
@ -902,13 +929,28 @@ console.log("收到设备的数据",data)
let p1 = these.HoldYouHand("video transmit start", 2200, f.deviceId, f.writeServiceId,
f.wirteCharactId);
let p2 = new Promise((succ, err) => {
const token = uni.getStorageSync('token');
const clientid = uni.getStorageSync('clientID');
if (!token) {
err({
code: 401,
msg: "请先登陆后再试"
});
hideLoading(these);
return;
}
uni.uploadFile({
url: 'http://114.55.111.217/video/upload',
// url: 'http://114.55.111.217/video/upload',
url: baseURL+"app/video/upload",
filePath: videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
"Content-Type": "multipart/form-data",
"Authorization": 'Bearer ' + token,
"clientid": clientid
},
timeout: 600000,
fail: (ex) => {
@ -1130,10 +1172,11 @@ console.log("收到设备的数据",data)
if (currentPacket > totalPackets) {
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f.writeServiceId, f
setTimeout(() => {
these.HoldYouHand("transmit complete", 0, f.deviceId, f
.writeServiceId, f
.wirteCharactId);
},500);
}, 500);
}
@ -1155,6 +1198,16 @@ console.log("收到设备的数据",data)
visibleClose: true
});
these.setBleFormData();
// let formdata = {
// code: these.formData.id,
// name: these.formData.name,
// position: these.formData.job,
// unitName: these.formData.company,
// deviceId: these.device.id,
// deviceImei: these.device.deviceImei
// };
// registerPersonInfo(formdata);
return;
}
@ -1219,7 +1272,7 @@ console.log("收到设备的数据",data)
}
if(ReSendNo){
if (ReSendNo) {
sendText(ReSendNo);
return;
}
@ -1261,6 +1314,7 @@ console.log("收到设备的数据",data)
}
console.log("开始握手");
let send = () => {
ble.sendData(deviceid, buffer, serviceid, characid, 10).then(
() => {
setTimeout(() => {
@ -1268,9 +1322,18 @@ console.log("收到设备的数据",data)
resolve(true);
}, pauseTime);
}).catch(err => {
console.log("握手没有成功", )
if (err.code == 10007) {
send();
} else {
console.log("握手没有成功", err)
reject(err);
}
});
}
send();
});

View File

@ -249,6 +249,14 @@
hideLoading,
updateLoading
} from '@/utils/loading.js'
import {
request,
baseURL
} from '../../utils/request';
import {
registerPersonInfo
} from '@/api/6170/deviceControl.js';
const pagePath = "pages/650/HBY650";
var ble = null;
var these = null;
@ -629,7 +637,7 @@
receiveData.modeCurr = staticLevelText;
receiveData.lightCurr = lightingLevelText;
receiveData.xuhang = json.sta_PowerTime + "分钟";
receiveData.battary = json.sta_PowerPercent ;
receiveData.battary = json.sta_PowerPercent;
receiveData.warnLevel = warn;
receiveData.staticWarn = staticWarn;
@ -699,10 +707,10 @@
},
getDevice: function() {
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
console.log("LinkedList=", ble.data.LinkedList);
console.log("this.device=", this.device);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
return v.macAddress == these.device.deviceMac;
});
return f;
@ -800,14 +808,14 @@
setTimeout(task, 0);
},
CloseWarn: function(ispop) {
let closeEvt=()=>{
let closeEvt = () => {
{
these.Status.Pop.showPop = false;
these.formData.qzwarn = false;
clearInterval(these.Status.staticWarn.inteval);
let closeSOS=()=>{
let closeSOS = () => {
let json = {
ins_SOSGrade: [0]
};
@ -816,7 +824,7 @@
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=",ex);
console.log("ex=", ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
@ -831,7 +839,7 @@
}
let closeWarn=()=>{
let closeWarn = () => {
let json = {
ins_ShakeBit: [0]
};
@ -840,7 +848,7 @@
this.sendMQ(json).then((res) => {
console.log("4g发送成功");
}).catch((ex) => {
console.log("ex=",ex);
console.log("ex=", ex);
these.showPop({
message: "通信异常,请检查手机或设备网络",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
@ -876,21 +884,22 @@
dataView.setUint8(3, 0x00); // 数据长度
dataView.setUint8(4, 0x01); // 数据长度
dataView.setUint8(5, 0x68);
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(()=>{
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10)
.then(() => {
console.log("成功");
});
}).catch(ex => {
closeSOS();
closeWarn();
// closeWarn();
});
} else {
closeSOS();
closeWarn();
// closeWarn();
}
}
}
if(!ispop){
if (!ispop) {
closeEvt();
return;
}
@ -901,7 +910,7 @@
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText:"解除报警",
buttonText: "解除报警",
okCallback: closeEvt
});
@ -972,21 +981,21 @@
() => {
console.log("蓝牙发送成功了");
dic = {
close: 0x71
}
if (type in dic) {
dataView.setUint8(1, 0x06); // 帧类型
dataView.setUint8(5, 0x71); // 数据
// dic = {
// close: 0x71
// }
// if (type in dic) {
// dataView.setUint8(1, 0x06); // 帧类型
// dataView.setUint8(5, 0x71); // 数据
} else {
dataView.setUint8(1, 0x06); // 帧类型
dataView.setUint8(5, 0x70); // 数据
}
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
10).then(() => {
console.log("蓝牙发送报警成功", type);
})
// } else {
// dataView.setUint8(1, 0x06); // 帧类型
// dataView.setUint8(5, 0x70); // 数据
// }
// ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
// 10).then(() => {
// console.log("蓝牙发送报警成功", type);
// })
hideLoading(these);
these.setBleFormData();
@ -1012,16 +1021,28 @@
okCallback: function() {
these.formData.qzwarn = true;
these.Status.staticWarn.time = 5;
these.Status.staticWarn.inteval = setInterval(() => {
these.Status.staticWarn.time = 180;
let loopFunc = () => {
if (these.Status.staticWarn.inteval === null) {
return;
}
if (these.Status.staticWarn.time === 0) {
console.log("111111");
clearInterval(these.Status.staticWarn.inteval);
these.Status.staticWarn.inteval = null;
these.formData.qzwarn = false;
these.formData.SOS = 'close';
these.CloseWarn(false);
return;
}
these.Status.staticWarn.time = these.Status.staticWarn
.time - 1;
}
these.Status.staticWarn.inteval = setInterval(() => {
loopFunc();
}, 1000)
SendCmd();
@ -1101,8 +1122,14 @@
these.setBleFormData();
}).catch((ex) => {
//使用4G发送
if (ex.code == 10007) {
console.log("蓝牙发送失败,正在重试");
task();
} else {
console.log("蓝牙发送失败,转4g发送", ex);
requestSend();
}
});
} else {
console.log("找不到蓝牙设备使用4G发送")
@ -1437,6 +1464,8 @@
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
let inteval = 30;
console.log("开始发送一段视频"); //
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
@ -1487,6 +1516,17 @@
}
var sendVideo = (videoPath) => {
let f = these.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接,请连接后再试",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
let uploadVideo = () => {
if (these.videoHexArray.length > 0) {
@ -1495,7 +1535,9 @@
return;
}
console.log("开始处理,正在上传");
console.log("开始处理,正在上传", f);
const token = uni.getStorageSync('token');
const clientid = uni.getStorageSync('clientID');
showLoading(these, {
text: "上传中"
@ -1503,13 +1545,25 @@
let p1 = these.HoldYouHand("video transmit start", 2200, f.deviceId, f.writeServiceId,
f.wirteCharactId);
let p2 = new Promise((succ, err) => {
if (!token) {
err({
code: 401,
msg: "请先登陆后再试"
});
hideLoading(these);
return;
}
console.log("baseURL=", baseURL);
uni.uploadFile({
url: 'http://114.55.111.217/video/upload',
// url: 'http://114.55.111.217/video/upload',
url: baseURL + "/app/video/upload",
filePath: videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
"Content-Type": "multipart/form-data",
"Authorization": 'Bearer ' + token,
"clientid": clientid
},
timeout: 600000,
fail: (ex) => {
@ -1564,7 +1618,7 @@
});
})
}
let f = these.getDevice();
@ -1818,6 +1872,17 @@
});
these.setBleFormData();
hideLoading(these);
// let formdata = {
// code: these.formData.usrid,
// name: these.formData.usrname,
// position: these.formData.job,
// unitName: these.formData.company,
// deviceId: these.device.id,
// deviceImei: these.device.deviceImei
// };
// registerPersonInfo(formdata);
return;
}

View File

@ -125,7 +125,8 @@
let start = new Date();
console.log("Common.baseURL=" + Common.baseURL);
uni.uploadFile({
url: Common.baseURL + 'video/upload',
// url: Common.baseURL + 'video/upload',
url:'http://192.168.110.56:8000/app/video/upload',
filePath: this.videoPath,
name: 'file',
header: {

View File

@ -35,11 +35,12 @@
updateLoading
} from '@/utils/loading.js';
const pagePath="pages/common/addBLE/LinkBle";
const pagePath = "pages/common/addBLE/LinkBle";
var these = null;
var eventChannel = null;
var ble = null;
var timeInteval = null;
export default {
data() {
return {
@ -57,7 +58,8 @@
],
"linkStatu": false,
"macAddress": ""
}
},
serverDevice:null
}
},
computed: {
@ -84,7 +86,7 @@
onLoad(option) {
these = this;
ble = bleTool.getBleTool();
ble.addReceiveCallback((receive,f,path) => {
ble.addReceiveCallback((receive, f, path) => {
console.log("收到设备消息,", receive);
if (these.device.deviceId == receive.deviceId) {
// console.log("11111");
@ -97,19 +99,19 @@
}
}
}
},pagePath);
}, pagePath);
eventChannel = this.getOpenerEventChannel();
eventChannel.on('LinkItem', function(data) {
console.log("data=",data);
console.log("data=", data);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == data.deviceId;
});
if (f) {
let keys=Object.keys(f);
keys.forEach((v,index)=>{
these.device[v]=f[v];
let keys = Object.keys(f);
keys.forEach((v, index) => {
these.device[v] = f[v];
})
console.log("LinkedList=",ble.data.LinkedList)
console.log("LinkedList=", ble.data.LinkedList)
console.log("f=", f);
console.log("获取到设备", these.device);
if (f.macAddress) {
@ -121,14 +123,19 @@
console.log("未获取到设备");
}
})
let inteval = setInterval(this.initDevice, 5000);
},
methods: {
initDevice: function() {
clearTimeout(timeInteval);
timeInteval = setTimeout(() => {
showLoading(these, {
text: '正在获取设备信息'
});
console.log("these.device=",these.device);
console.log("these.device=", these.device);
request({
url: '/app/device/getDeviceInfoByDeviceMac',
method: 'GET',
@ -139,13 +146,17 @@
console.log("获取设备信息", res);
if (res && res.code == 200) {
let data = res.data;
this.serverDevice=data;
if (data) {
let keys = Object.keys(data);
ble.data.LinkedList.find((v) => {
if(v.deviceId == these.device.deviceId){
if (v.deviceId == these.device.deviceId) {
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
v[key] = data[key];
// let key = keys[i];
// if(!v.device){
// v.device={};
// }
// v.device[key] = data[key];
// console.log("key="+key);
// console.log("value="+data[key]);
@ -154,12 +165,12 @@
}
ble.setBleData();
// ble.setBleData();
}
});
console.log("device=",these.device);
console.log("LinkedList=",ble.data.LinkedList);
console.log("device=", these.device);
console.log("LinkedList=", ble.data.LinkedList);
}
@ -170,6 +181,9 @@
}).finally(() => {
hideLoading(these);
});
}, 500);
},
Link() {
// 调用绑定设备接口
@ -207,6 +221,21 @@
if (res.code == 200) {
these.Statu.bound = true;
these.Statu.boundRemark = "设备绑定成功!";
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.device.deviceId) {
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if(!v.device){
v.device={};
}
v.device[key] = data[key];
}
ble.setBleData();
}
});
ble.removeReceiveCallback(pagePath);
uni.$emit("refreshDeviceList");

View File

@ -1,8 +1,8 @@
var isReady=false;var onReadyCallbacks=[];
var isServiceReady=false;var onServiceReadyCallbacks=[];
var __uniConfig = {"pages":["pages/BlueTooth/ModeSetting/index","pages/common/login/index","pages/common/index/index","pages/common/user/index","pages/common/scan/scan","pages/common/qrcode/qrcode","pages/common/send/index","pages/common/userAgreement/index","pages/common/privacyAgreement/index","pages/common/aboutUs/index","pages/6170/deviceControl/index","pages/6170/callPolice/index","pages/210/deviceControl/index","pages/common/operationVideo/index","pages/common/addvideo/index","pages/common/operatingInstruct/index","pages/common/productDes/index","pages/common/addBLE/addEquip","pages/common/addBLE/LinkBle","pages/6155/deviceDetail","pages/6155/ImgCrop","pages/common/map/index","pages/common/allType/index","pages/6170/allShare/index","pages/6170/share/index","pages/6170/shareDevices/index","pages/6170/shareManagement/index","pages/210/onlineDevice/index","pages/210/addDevice/index","pages/210/historyRecords/index","pages/210/call/index","pages/BlueTooth/ModeSetting/VideoSend","pages/BlueTooth/ModeSetting/VideoSend_1","pages/BlueTooth/ModeSetting/VideoSend_670","pages/BlueTooth/ModeSetting/HBY650","pages/BlueTooth/ModeSetting/HBY650_1","pages/BlueTooth/ModeSetting/ModeSetting","pages/BlueTooth/ModeSetting/update","pages/BlueTooth/ModeSetting/HBY6155","pages/BlueTooth/ModeSetting/HBY6155V1","pages/BlueTooth/ModeSetting/HBY670V1","pages/670/HBY670","pages/650/HBY650","pages/670/History","pages/BlueTooth/ModeSetting/4877"],"window":{"navigationBarTextStyle":"white","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#121212","backgroundColor":"#121212"},"tabBar":{"color":"#fff","selectedColor":"#BBE600","backgroundColor":"#202020","list":[{"pagePath":"pages/common/index/index","text":"我的设备","iconPath":"/static/tabs/device.png","selectedIconPath":"/static/tabs/device-HL.png"},{"pagePath":"pages/common/user/index","text":"我的","iconPath":"/static/tabs/my.png","selectedIconPath":"/static/tabs/my-HL.png"}]},"darkmode":false,"nvueCompiler":"uni-app","nvueStyleCompiler":"uni-app","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"JingQuan","compilerVersion":"4.75","entryPagePath":"pages/BlueTooth/ModeSetting/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/BlueTooth/ModeSetting/index","meta":{"isQuit":true},"window":{"navigationBarTitleText":"设备类型"}},{"path":"/pages/common/login/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/index/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationStyle":"custom","enablePullDownRefresh":true}},{"path":"/pages/common/user/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationBarTitleText":"我的"}},{"path":"/pages/common/scan/scan","meta":{},"window":{"navigationBarTitleText":"扫描"}},{"path":"/pages/common/qrcode/qrcode","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/common/send/index","meta":{},"window":{"navigationBarTitleText":"发送信息","enablePullDownRefresh":true}},{"path":"/pages/common/userAgreement/index","meta":{},"window":{"navigationBarTitleText":"用户协议"}},{"path":"/pages/common/privacyAgreement/index","meta":{},"window":{"navigationBarTitleText":"隐私协议"}},{"path":"/pages/common/aboutUs/index","meta":{},"window":{"navigationBarTitleText":"关于我们"}},{"path":"/pages/6170/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/6170/callPolice/index","meta":{},"window":{"navigationBarTitleText":"报警","enablePullDownRefresh":true}},{"path":"/pages/210/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operationVideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addvideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operatingInstruct/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/productDes/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addBLE/addEquip","meta":{},"window":{"navigationBarTitleText":"添加设备"}},{"path":"/pages/common/addBLE/LinkBle","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/6155/deviceDetail","meta":{},"window":{"navigationBarTitleText":"HBY 6155"}},{"path":"/pages/6155/ImgCrop","meta":{},"window":{"navigationBarTitleText":"图像裁剪","navigationStyle":"custom","fullscreen":true}},{"path":"/pages/common/map/index","meta":{},"window":{"navigationBarTitleText":"地图"}},{"path":"/pages/common/allType/index","meta":{},"window":{"navigationBarTitleText":"所有类型"}},{"path":"/pages/6170/allShare/index","meta":{},"window":{"navigationBarTitleText":"所有分享"}},{"path":"/pages/6170/share/index","meta":{},"window":{"navigationBarTitleText":"分享"}},{"path":"/pages/6170/shareDevices/index","meta":{},"window":{"navigationBarTitleText":"分享设备"}},{"path":"/pages/6170/shareManagement/index","meta":{},"window":{"navigationBarTitleText":"分享管理"}},{"path":"/pages/210/onlineDevice/index","meta":{},"window":{"navigationBarTitleText":"联机设备"}},{"path":"/pages/210/addDevice/index","meta":{},"window":{"navigationBarTitleText":"添加联机设备"}},{"path":"/pages/210/historyRecords/index","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/210/call/index","meta":{},"window":{"navigationBarTitleText":"呼叫"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend_1","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend_670","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/HBY650","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/BlueTooth/ModeSetting/HBY650_1","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/BlueTooth/ModeSetting/ModeSetting","meta":{},"window":{"navigationBarTitleText":"7307-0.96TFT"}},{"path":"/pages/BlueTooth/ModeSetting/update","meta":{},"window":{"navigationBarTitleText":"版本更新"}},{"path":"/pages/BlueTooth/ModeSetting/HBY6155","meta":{},"window":{"navigationBarTitleText":"HBY6155"}},{"path":"/pages/BlueTooth/ModeSetting/HBY6155V1","meta":{},"window":{"navigationBarTitleText":"HBY6155_V1"}},{"path":"/pages/BlueTooth/ModeSetting/HBY670V1","meta":{},"window":{"navigationBarTitleText":"HBY670"}},{"path":"/pages/670/HBY670","meta":{},"window":{"navigationBarTitleText":"HBY670","navigationStyle":"custom"}},{"path":"/pages/650/HBY650","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/670/History","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/BlueTooth/ModeSetting/4877","meta":{},"window":{"navigationBarTitleText":""}}];
var __uniConfig = {"pages":["pages/common/login/index","pages/common/index/index","pages/common/user/index","pages/common/scan/scan","pages/common/qrcode/qrcode","pages/common/send/index","pages/common/userAgreement/index","pages/common/privacyAgreement/index","pages/common/aboutUs/index","pages/6170/deviceControl/index","pages/6170/callPolice/index","pages/210/deviceControl/index","pages/common/operationVideo/index","pages/common/addvideo/index","pages/common/operatingInstruct/index","pages/common/productDes/index","pages/common/addBLE/addEquip","pages/common/addBLE/LinkBle","pages/6155/deviceDetail","pages/6155/ImgCrop","pages/common/map/index","pages/common/allType/index","pages/6170/allShare/index","pages/6170/share/index","pages/6170/shareDevices/index","pages/6170/shareManagement/index","pages/210/onlineDevice/index","pages/210/addDevice/index","pages/210/historyRecords/index","pages/210/call/index","pages/BlueTooth/ModeSetting/VideoSend","pages/BlueTooth/ModeSetting/VideoSend_1","pages/BlueTooth/ModeSetting/VideoSend_670","pages/BlueTooth/ModeSetting/HBY650","pages/BlueTooth/ModeSetting/HBY650_1","pages/BlueTooth/ModeSetting/ModeSetting","pages/BlueTooth/ModeSetting/update","pages/BlueTooth/ModeSetting/HBY6155","pages/BlueTooth/ModeSetting/HBY6155V1","pages/BlueTooth/ModeSetting/HBY670V1","pages/670/HBY670","pages/650/HBY650","pages/670/History","pages/BlueTooth/ModeSetting/4877"],"window":{"navigationBarTextStyle":"white","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#121212","backgroundColor":"#121212"},"tabBar":{"color":"#fff","selectedColor":"#BBE600","backgroundColor":"#202020","list":[{"pagePath":"pages/common/index/index","text":"我的设备","iconPath":"/static/tabs/device.png","selectedIconPath":"/static/tabs/device-HL.png"},{"pagePath":"pages/common/user/index","text":"我的","iconPath":"/static/tabs/my.png","selectedIconPath":"/static/tabs/my-HL.png"}]},"darkmode":false,"nvueCompiler":"uni-app","nvueStyleCompiler":"uni-app","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"星汉物联","compilerVersion":"4.75","entryPagePath":"pages/common/login/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/common/login/index","meta":{"isQuit":true},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/index/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationStyle":"custom","enablePullDownRefresh":true}},{"path":"/pages/common/user/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationBarTitleText":"我的"}},{"path":"/pages/common/scan/scan","meta":{},"window":{"navigationBarTitleText":"扫描"}},{"path":"/pages/common/qrcode/qrcode","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/common/send/index","meta":{},"window":{"navigationBarTitleText":"发送信息","enablePullDownRefresh":true}},{"path":"/pages/common/userAgreement/index","meta":{},"window":{"navigationBarTitleText":"用户协议"}},{"path":"/pages/common/privacyAgreement/index","meta":{},"window":{"navigationBarTitleText":"隐私协议"}},{"path":"/pages/common/aboutUs/index","meta":{},"window":{"navigationBarTitleText":"关于我们"}},{"path":"/pages/6170/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/6170/callPolice/index","meta":{},"window":{"navigationBarTitleText":"报警","enablePullDownRefresh":true}},{"path":"/pages/210/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operationVideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addvideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operatingInstruct/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/productDes/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addBLE/addEquip","meta":{},"window":{"navigationBarTitleText":"添加设备"}},{"path":"/pages/common/addBLE/LinkBle","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/6155/deviceDetail","meta":{},"window":{"navigationBarTitleText":"HBY 6155"}},{"path":"/pages/6155/ImgCrop","meta":{},"window":{"navigationBarTitleText":"图像裁剪","navigationStyle":"custom","fullscreen":true}},{"path":"/pages/common/map/index","meta":{},"window":{"navigationBarTitleText":"地图"}},{"path":"/pages/common/allType/index","meta":{},"window":{"navigationBarTitleText":"所有类型"}},{"path":"/pages/6170/allShare/index","meta":{},"window":{"navigationBarTitleText":"所有分享"}},{"path":"/pages/6170/share/index","meta":{},"window":{"navigationBarTitleText":"分享"}},{"path":"/pages/6170/shareDevices/index","meta":{},"window":{"navigationBarTitleText":"分享设备"}},{"path":"/pages/6170/shareManagement/index","meta":{},"window":{"navigationBarTitleText":"分享管理"}},{"path":"/pages/210/onlineDevice/index","meta":{},"window":{"navigationBarTitleText":"联机设备"}},{"path":"/pages/210/addDevice/index","meta":{},"window":{"navigationBarTitleText":"添加联机设备"}},{"path":"/pages/210/historyRecords/index","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/210/call/index","meta":{},"window":{"navigationBarTitleText":"呼叫"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend_1","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend_670","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/HBY650","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/BlueTooth/ModeSetting/HBY650_1","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/BlueTooth/ModeSetting/ModeSetting","meta":{},"window":{"navigationBarTitleText":"7307-0.96TFT"}},{"path":"/pages/BlueTooth/ModeSetting/update","meta":{},"window":{"navigationBarTitleText":"版本更新"}},{"path":"/pages/BlueTooth/ModeSetting/HBY6155","meta":{},"window":{"navigationBarTitleText":"HBY6155"}},{"path":"/pages/BlueTooth/ModeSetting/HBY6155V1","meta":{},"window":{"navigationBarTitleText":"HBY6155_V1"}},{"path":"/pages/BlueTooth/ModeSetting/HBY670V1","meta":{},"window":{"navigationBarTitleText":"HBY670"}},{"path":"/pages/670/HBY670","meta":{},"window":{"navigationBarTitleText":"HBY670","navigationStyle":"custom"}},{"path":"/pages/650/HBY650","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/670/History","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/BlueTooth/ModeSetting/4877","meta":{},"window":{"navigationBarTitleText":""}}];
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,global:void 0,window:void 0,document:void 0,frames:void 0,self:void 0,location:void 0,navigator:void 0,localStorage:void 0,history:void 0,Caches:void 0,screen:void 0,alert:void 0,confirm:void 0,prompt:void 0,fetch:void 0,XMLHttpRequest:void 0,WebSocket:void 0,webkit:void 0,print:void 0}}}});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -40,8 +40,8 @@ class BleHelper {
onDeviceFound: [], //发现新设备的事件
receivDataCallback: [] //接收到数据的事件
}
this.addReceiveCallback((a,b,c)=>{
recei.ReceiveData(a,b,c);
this.addReceiveCallback((a, b, c) => {
recei.ReceiveData(a, b, c);
}, "BleReceiveData");
this.dic = {
errRemarks: [{
@ -105,15 +105,18 @@ 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);
if(device.macAddress && device.device && device.device.id){
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
.notifyCharactId);
}
}
} else {
// console.log("无设备连接");
}
@ -335,8 +338,8 @@ class BleHelper {
}
uni.getBluetoothAdapterState({
success: (info) => {
this.data.available=info.available;
this.data.discovering=info.discovering;
this.data.available = info.available;
this.data.discovering = info.discovering;
resolve(info);
},
fail: (ex1) => {
@ -365,7 +368,7 @@ class BleHelper {
success: (args) => {
// console.log("蓝牙初始化成功:" + JSON.stringify(args));
this.data.isOpenBlue = true;
this.data.available=true;
this.data.available = true;
resolve(true);
if (this.data.isSubscribe) { //整个App生命周期只订阅一次
@ -386,7 +389,7 @@ class BleHelper {
this.data.discovering = state.discovering;
if (this.data.available && this.data
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
this.linkAllDevices();
}
@ -437,8 +440,8 @@ class BleHelper {
uni.onBLECharacteristicValueChange((receive) => {
//订阅消息
console.log("收到订阅消息",receive);
let f=this.data.LinkedList.find((v) => {
console.log("收到订阅消息", receive);
let f = this.data.LinkedList.find((v) => {
return v.deviceId == receive.deviceId;
})
let dataView = new DataView(receive.value);
@ -477,7 +480,7 @@ class BleHelper {
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
console.log("收到mac地址:", bytes)
if (bytes.length >= 7) {
console.log("hexs=",hexs);
console.log("hexs=", hexs);
let mac = hexs.slice(1, 7).join(":")
.toUpperCase();
this.data.LinkedList.find((v) => {
@ -491,7 +494,7 @@ class BleHelper {
.data.LinkedList);
}
}
console.log("str=",str);
console.log("str=", str);
} catch (ex) {
console.log("将数据转文本失败", ex);
}
@ -672,7 +675,8 @@ class BleHelper {
}
// console.log("c=", c);
let startSubScribe = (id, serviceId, characteristicId) => {
console.log("serviceId=",serviceId);
console.log("characteristicId=",characteristicId);
return new Promise((succ, err) => {
uni.notifyBLECharacteristicValueChange({
deviceId: id,
@ -681,7 +685,7 @@ class BleHelper {
state: state,
success: (res) => {
if (state) {
// console.log("订阅消息成功", res);
console.log("订阅消息成功", res);
} else {
console.log("取消订阅成功", res);
}
@ -701,6 +705,7 @@ class BleHelper {
});
}
let promies = new Array();
if(c.Characteristics && c.Characteristics.length){
for (var i = 0; i < c.Characteristics.length; i++) {
let item = c.Characteristics[i];
let serviceId = item.serviceId;
@ -710,15 +715,17 @@ class BleHelper {
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
}
}
}
if (promies.length > 0) {
Promise.allSettled(promies).then((results) => {
results.forEach((result, index) => {
if (result.status === "fulfilled") {
//console.log(`操作${index + 1}成功:`, result.value);
console.log(`操作${index + 1}成功:`, result.value);
} else {
// console.log(`操作${index + 1}失败:`, result.reason
// .message);
console.log(`操作${index + 1}失败:`, result.reason
.message);
}
});
@ -732,7 +739,7 @@ class BleHelper {
}, 20);
}, 800);
});
}
@ -939,23 +946,28 @@ class BleHelper {
//连接设备
var linkDevice = () => {
return new Promise((resolve, reject) => {
// 添加重试次数限制
let retryCount = 0;
const maxRetries = 10; // 最大重试次数
const connect = () => {
return new Promise((resolve, reject) => {
if (fIndex > -1 && f?.Linked) {
console.log("当前已连接,跳过其他步骤")
console.log("当前已连接,跳过其他步骤");
resolve(false);
return;
}
if(!this.data.available){
reject(this.getError({code:10001}));
if (!this.data.available) {
reject(this.getError({ code: 10001 }));
return;
}
console.log("正在连接" + deviceId);
uni.createBLEConnection({
deviceId: deviceId,
timeout: 30000,
success: (info) => {
console.log("新连接成功", this.data.LinkedList);
this.getLinkBlue().then((arr) => {
let cr = arr.devices.find(c => {
@ -964,54 +976,60 @@ class BleHelper {
return true;
}
return false;
});
if (fIndex > -1) {
this.data.LinkedList[fIndex].Linked = true;
} else {
this.data.LinkedList.push(cr);
}
uni.setStorageSync(this.StorageKey, this.data
.LinkedList);
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
console.log("LinkedList=", this.data.LinkedList);
let os = plus.os.name;
console.log("os=",os);
if (os == 'Android') {
// 处理 MTU 设置
if (plus.os.name === 'Android') {
uni.setBLEMTU({
deviceId: deviceId,
mtu: 512,
success: (mtu) => {
console.log("mtu设置成功",mtu);
console.log("mtu设置成功", mtu);
resolve(true);
},
fail: () => {
console.log("mtu设置失败")
resolve(true);
},
finally:()=>{
console.log("mtu设置失败");
resolve(true); // MTU设置失败不影响连接成功
}
});
}else{
} else {
resolve(true);
}
}).catch((ex) => {
reject(this.getError(ex));
});
},
fail: (ex) => {
ex = this.getError(ex)
ex = this.getError(ex);
console.log("蓝牙连接失败" + JSON.stringify(ex));
// 连接超时后自动重试
if (ex.code === 10012 && retryCount < maxRetries) {
retryCount++;
console.log(`重试连接 (${retryCount}/${maxRetries})`);
// 使用 setTimeout 避免递归调用栈溢出
setTimeout(() => {
connect().then(resolve).catch(reject);
}, 1000); // 延迟1秒后重试
} else {
reject(ex);
}
});
});
}
});
});
};
return connect();
};
@ -1021,19 +1039,32 @@ class BleHelper {
////console.log("2222222");
return linkDevice(deviceId);
}).then((res) => {
////console.log("11111111");
if (res) { //新连接
console.log("11111111");
if (fIndex == -1) {
console.log("开始获取服务", targetServiceId)
return this.getService(deviceId, targetServiceId, writeCharId,
notifyCharId); //获取服务
} else {
if(f.wirteCharactId && f.notifyCharactId){
if (!f.notifyState) {
console.log("开始订阅特征");
this.subScribe(deviceId, true);
}else{
console.log("不订阅消息");
}
return Promise.resolve(true);
}else{
console.log("开始获取服务", targetServiceId)
return this.getService(deviceId, targetServiceId, writeCharId,
notifyCharId);
}
}
} else { //已连接过,直接订阅消息
console.log("11111111");
if (fIndex > -1 && f && !f.notifyState) {
this.subScribe(deviceId, true);