diff --git a/App.vue b/App.vue index bb9d0c3..04e9188 100644 --- a/App.vue +++ b/App.vue @@ -5,8 +5,31 @@ export default { onLaunch: function() { + var ble = bleTool.getBleTool(); + //以下代码仅在开发时使用,否则会出现不可预知的问题。 // uni.clearStorageSync(); - var ble = bleTool.getBleTool(); + // 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); + // } + // }); + + }, onShow: function() { console.log('App Show'); diff --git a/api/6155/BlueHelper.js b/api/6155/BlueHelper.js deleted file mode 100644 index a855d9e..0000000 --- a/api/6155/BlueHelper.js +++ /dev/null @@ -1,708 +0,0 @@ -export default { - featrueValueCallback: null, //蓝牙特征变化回调 - BleChangeCallback: null, //蓝牙状态变化回调 - //引导用户打开蓝牙 - showBluetoothGuide: function(showTip) { - let platform = process.env.UNI_PLATFORM; - - - var openBlueSetting = function() { - // 判断平台类型 - if (platform === 'mp-weixin') { - uni.openSetting(); - } else if (platform === 'app-plus' || platform === 'app') { - //---------------------------------------------------------------- - const osName = plus.os.name; - - if (osName === 'iOS') { - // iOS 平台打开蓝牙设置 - plus.runtime.openURL('App-Prefs:root=Bluetooth', function() { - console.log('成功打开蓝牙设置'); - }, function(err) { - console.error('打开蓝牙设置失败:' + err.message); - uni.showModal({ - title: '提示', - content: '无法自动打开蓝牙设置,请手动前往设置 > 蓝牙 进行操作。', - showCancel: false - }); - }); - } else if (osName === 'Android') { - // Android 平台打开蓝牙设置 - try { - const Intent = plus.android.importClass('android.content.Intent'); - const Settings = plus.android.importClass('android.provider.Settings'); - const main = plus.android.runtimeMainActivity(); - const intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS); - main.startActivity(intent); - } catch (e) { - console.error('打开蓝牙设置失败:' + e.message); - // 尝试使用通用设置页面作为备选方案 - plus.runtime.openURL('settings://', function() { - console.log('打开系统设置成功,请手动找到蓝牙选项'); - }, function() { - uni.showModal({ - title: '提示', - content: '无法自动打开蓝牙设置,请手动前往设置页面开启蓝牙。', - showCancel: false - }); - }); - } - } else { - uni.showModal({ - title: '提示', - content: '当前系统不支持自动打开蓝牙设置,请手动操作。', - showCancel: false - }); - } - - - //-------------------------------------------------------------------- - } else if (platform === 'mp-alipay') { - uni.openSetting(); - } - - } - - if (showTip !== undefined) { - openBlueSetting(); - return; - } - if (platform === 'mp-weixin' || platform === 'app-plus' || platform === 'mp-alipay' || platform === 'app') { - uni.showModal({ - title: '蓝牙未开启', - content: '请在系统设置中打开蓝牙以使用此功能', - success: (res) => { - if (res.confirm) { - openBlueSetting(); - } - } - }); - } else { - console.log("当前平台不支持打开系统设置" + platform); - } - - - }, - //获取蓝牙适配器状态 - CheckBlue: function(callback) { - - uni.getBluetoothAdapterState({ - success(res1) { - - //console.log("当前蓝牙适配器状态:" + JSON.stringify(res1)) - if (callback) { - callback(res1); - } - - }, - fail(ex1) { - console.log("检查蓝牙状态异常:" + JSON.stringify(ex1)); - if (callback) { - if (ex1.code == 10000) { - console.log("未初始化蓝牙适配器"); - } - let res1 = { - available: false, - discovering: false - } - callback(res1); - } - }, - complete() { - - } - }); - }, - //初始化蓝牙模块 - OpenBlue: function(isCheckState, callback, availCallback) { - - var these = this; - - var init = function() { - uni.openBluetoothAdapter({ - success: (res) => { - console.log("蓝牙初始化成功:" + JSON.stringify(res)); - if (callback) { - callback(); - } - uni.onBluetoothAdapterStateChange(function(state) { - //console.log('蓝牙状态发生变化:' + JSON.stringify(state)); - if (this.BleChangeCallback) { - this.BleChangeCallback() - } - }) - }, - fail: function(ex2) { - console.log("蓝牙初始化失败:" + JSON.stringify(ex2)) - if (ex2.code == '10001') { - console.log("手机蓝牙未打开或设备不支持蓝牙"); - - - if (availCallback) { - availCallback(); - } else { - these.showBluetoothGuide(); - } - } - } - }); - } - if (isCheckState) { - this.CheckBlue(function(res1) { - if (res1.available) { - if (callback) { - callback(); - } - return; - } - init(); - }) - } else { - init(); - } - - - - }, - //关闭蓝牙模块,停止搜索、断开所有连接 - CloseBlue: function(callback) { - - this.StopSearch(); - - this.disconnectDevice(); - - uni.closeBluetoothAdapter({ - success: () => { - console.log("蓝牙模块已关闭"); - if (callback) { - callback(); - } - } - }); - }, - //开始搜索新设备 - StartSearch: function(callback) { - - var these = this; - - //发现新设备 - var onDeviceFound = function() { - uni.onBluetoothDeviceFound(function(res) { - console.log("发现新设备:" + JSON.stringify(res)); - if (callback) { - callback(res); - } - }) - } - //开始搜索 - var Search = function() { - uni.startBluetoothDevicesDiscovery({ - services: ["0xFFE0"], - allowDuplicatesKey: false, - success: (res) => { - console.log('开始搜索蓝牙设备成功'); - onDeviceFound(); - }, - fail: (err) => { - console.log(`搜索蓝牙设备失败: ${err.errMsg}`); - } - }); - - } - //先检查蓝牙状态是可用 - this.CheckBlue(function(res1) { - if (res1.available) { - if (!res1.discovering) { - Search(); - } else { - console.log("当前蓝牙正在搜索设备") - } - - } else { - these.OpenBlue(false, Search, () => { - these.showBluetoothGuide(); - }); - } - }); - - - - }, - //停止搜索 - StopSearch: function() { - uni.stopBluetoothDevicesDiscovery({ - success: (res) => { - //console.log("停止搜索蓝牙设备成功") - }, - fail() { - console.log("无法停止蓝牙搜索") - } - }); - }, - //获取已连接的设备 - getLinkBlue: function(callback) { - uni.getConnectedBluetoothDevices({ - success: (res) => { - if (callback) { - callback(res); - - } - }, - fail: function(ex) { - console.log("获取已连接设备异常",ex); - if (callback) { - callback({ - devices: [] - }); - } - } - }) - }, - //连接某个设备 - LinkBlue: function(deviceId, callback, error) { - //console.log("deviceId="+deviceId) - this.StopSearch(); - var these = this; - let key = "linkedDevices"; - var store = uni.getStorageInfoSync(); - var f = store.keys.find(function(v) { - return v == key; - }); - var linkedDevices = []; - if (f) { - var str = uni.getStorageSync(key); - if (str) { - linkedDevices = JSON.parse(str); - } else { - linkedDevices = []; - } - - } - //连接成功的回调 - var lindedCallback = function(id,flag) { - - let c = linkedDevices.find(function(v) { - return v.deviceId == deviceId; - }); - - if (c && !flag) { - console.log("连接成功开始监听特征变化,deviceid="+deviceId+',serviceId='+c.notifyServiceid+',characteristicId='+c.notifyCharactId) - //监听设备的特征变化 - setTimeout(()=>{ - uni.notifyBLECharacteristicValueChange({ - deviceId: deviceId, - serviceId: c.notifyServiceid, - characteristicId: c.notifyCharactId, - state: true, - success: function(res) { - console.log("开始监听成功。。。。",res) - //订阅特征值 - - uni.onBLECharacteristicValueChange(function(data) { - // data.characteristicId - // data.deviceId - // data.serviceId - // data.value - console.log("监听到特征值:" + JSON.stringify(data)); - - if (these.featrueValueCallback) { - these.featrueValueCallback(data); - } - }); - - - } - }); - - },1000); - - } - - if (callback) { - callback(deviceId,flag); - } - } - - var linkState = function(res) { - //console.log("获取已连接的设备回调" + JSON.stringify(res)) - let flag = res.devices.find(function(v) { - if (v.deviceId == deviceId) { - return true; - } - return false; - }); - if (flag) { - //console.log("设备状态已连接"); - - lindedCallback(deviceId,true); - - return; - } else { - console.log("设备未连接:"+deviceId); - linkDevice(deviceId); - } - } - - var linkDevice = function() { - console.log("正在连接" + deviceId); - uni.createBLEConnection({ - deviceId: deviceId, - timeout: 30000, - success: function(info) { - - console.log("连接成功"); - - var call = () => { - if (linkedDevices) { - console.log("11111" + JSON.stringify(linkedDevices)); - f = linkedDevices.find(function(v) { - return v.deviceId == deviceId; - }); - } else { - console.log("22222") - f = null; - } - - - - if (!f) { - console.log("缓存中没有找到该设备") - - these.getLinkBlue(function(res) { - if (res.devices && res.devices.length) { - let f = res.devices.find(function(v) { - return v.deviceId == deviceId; - }); - linkedDevices.push(f); - uni.setStorageSync(key, JSON.stringify( - linkedDevices)); - - getService(deviceId); - - } - - }); - - - } else { - console.log("缓存中已连接过"); - if (!f.services) { - getService(deviceId); - } else { - - lindedCallback(deviceId,false); - - } - } - - } - let os = uni.getSystemInfoSync().osName; - if (os == 'android') { - uni.setBLEMTU({ - deviceId: deviceId, - mtu: 512, - success: () => { - //console.log("mtu设置成功"); - }, - fail: function() { - console.log("mtu设置失败") - }, - complete: function() { - call(); - } - }); - } else { - call(); - } - - }, - fail: function(ex) { - if (ex) { - console.log("蓝牙连接失败" + JSON.stringify(ex)); - if(error){ - error(ex); - } - - } - } - }); - } - //获取服务 - var getService = function(id) { - - var repeatCnt = 0; - var startgetService = function() { - uni.getBLEDeviceServices({ - deviceId: id, - success: function(res) { - if (res.services && res.services.length > 0) { - console.log("获取到服务:" + JSON.stringify(res)); - - linkedDevices.find(function(v) { - if (v.deviceId == id) { - v.services = res.services; - } - }); - uni.setStorageSync(key, JSON.stringify(linkedDevices)); - var promises = []; - for (var i = 0; i < res.services.length; i++) { - let service = res.services[i]; - promises.push(getFeatrus(id, service.uuid)); - } - - Promise.all(promises) - .then(results => { - console.log('所有操作成功完成', results); - - lindedCallback(id,false); - - }) - .catch(error => { - console.error('至少一个操作失败', error); - }); - - - } else { - repeatCnt++; - if (repeatCnt > 5) { - - lindedCallback(id,false); - - return; - } - setTimeout(function() { - startgetService(id); - }, 500); - } - } - }) - } - - setTimeout(function() { - startgetService(id); - }, 1000); - } - //获取特性 - var getFeatrus = function(id, serviceId) { - var promise = new Promise((resolve, reject) => { - uni.getBLEDeviceCharacteristics({ - deviceId: id, - serviceId: serviceId, - success: (res) => { - console.log("获取到特征:" + JSON.stringify(res)); - - //写特征 - let writeChar = res.characteristics.find(char => - char.uuid.indexOf("FFE1") > -1 - ); - //通知特征 - let notiChar = res.characteristics.find(char => - char.uuid.indexOf("FFE2") > -1 - ); - - linkedDevices.find(function(v) { - if (v.deviceId == id) { - if (!v.Characteristics) { - v.Characteristics = []; - } - v.Characteristics = v.Characteristics.concat(res - .characteristics); - - if (writeChar) { - v.writeServiceId = serviceId; - v.wirteCharactId = writeChar.uuid; - } - - if (notiChar) { - v.notifyServiceid = serviceId; - v.notifyCharactId = notiChar.uuid; - - - } - } - }); - - - - uni.setStorageSync(key, JSON.stringify(linkedDevices)); - resolve(res); - }, - fail: (ex) => { - console.log("获取特征出现异常:" + JSON.stringify(ex)); - resolve(ex); - } - }); - }); - return promise; - } - - //监测蓝牙状态变化 - uni.onBLEConnectionStateChange(function(res) { - if (!res.connected) { - console.log("蓝牙断开连接" + res.deviceId + ""); - // lindDevice(res.deviceId); - } - }); - - //console.log("正在获取蓝牙适配器状态") - this.CheckBlue((res) => { - //console.log("蓝牙状态:" + JSON.stringify(res)); - if (res.available) { - this.getLinkBlue(linkState); - } else { - console.log("蓝牙适配器不可用,正在初始化"); - this.OpenBlue(false, () => { - this.getLinkBlue(linkState); - }, () => { - console.log("请引导用户打开蓝牙"); - these.showBluetoothGuide(); - }) - } - - }); - - - }, - //断开连接 - disconnectDevice: function(deviceId) { - - var disconnect = function(id) { - uni.closeBLEConnection({ - deviceId: id, - success: (res) => { - console.log("蓝牙连接已断开"); - - } - }); - } - if (deviceId) { - disconnect(deviceId); - return; - } - //断开所有已连接的设备 - this.getLinkBlue(function(res) { - if (res.devices && res.devices.length > 0) { - for (var i = 0; i < res.devices.length; i++) { - let item = res.devices[i]; - disconnect(item.deviceId); - } - - } else { - console.log("无连接设备"); - } - }); - - }, - //发送二进制数据 - sendData: function(deviceid, buffer) { - - console.log("准备向设备发送数据,deviceid=" + deviceid); - return new Promise((resolve, reject) => { - if (!deviceid) { - reject(`deviceid为空,请输入要发送的设备`); - return; - } - console.log("准备发送数据包"); - let key = "linkedDevices"; - var store = uni.getStorageInfoSync(); - var f = store.keys.find(function(v) { - return v == key; - }); - console.log("倒计时:5"); - var linkedDevices = []; - if (f) { - var str = uni.getStorageSync(key); - if (str) { - linkedDevices = JSON.parse(str); - } - - } - console.log("倒计时:4"); - if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) { - console.log("倒计时:3"); - f = linkedDevices.find(function(v) { - return v.deviceId == deviceid; - - }); - console.log("f=" + JSON.stringify(f)); - // console.log("deviceid=" + deviceid); - console.log("倒计时:2"); - if (f) { - console.log("倒计时:1"); - these.sendDataNew(f.deviceId,f.writeServiceId,f.wirteCharactId,buffer).then(succ).catch(err); - } else { - reject(`已连接设备中无法找到此设备`); - // console.log("警报:已连接设备中无法找到此设备") - } - - } else { - console.log("检测到未与设备建立连接"); - reject(`检测到未与设备建立连接`); - } - - - }); - - - }, - sendDataNew: function(deviceid, serviceId, characteristicId, buffer) { - - //console.log("准备向设备发送数据,deviceid=" + deviceid+',serviceId='+serviceId+',characteristicId='+characteristicId); - return new Promise((resolve, reject) => { - let promise = new Promise((succ, err) => { - uni.writeBLECharacteristicValue({ - deviceId: deviceid, - serviceId: serviceId, - characteristicId: characteristicId, - value: buffer, - success: () => { - //console.log("发送数据成功"); - succ(); - }, - fail: (ex) => { - console.log("发送数据失败" + JSON.stringify(ex)); - err(ex); - } - }); - - }); - - if (uni.getSystemInfoSync().osName.toLowerCase() == 'ios') { - - //专业给IOS填坑,uni.writeBLECharacteristicValue在IOS上不进入任何回调 - - function timeout(ms) { - return new Promise((_, err) => { - setTimeout(() => { - err({ - code: -1, - errMsg: '超时了' - }) - }, ms); - }); - } - - Promise.race([promise, timeout(50)]).then(resolve).catch((ex) => { - console.log("ex=", ex); - if (ex.code == -1) { - resolve(); - } else { - reject(ex); - } - - }).finally(() => { - console.log("完成了") - }); - } else { - promise.then(resolve).catch(reject); - } - - - - }); - - - - } - -} \ No newline at end of file diff --git a/api/670/HBY670.js b/api/670/HBY670.js new file mode 100644 index 0000000..2f2ee24 --- /dev/null +++ b/api/670/HBY670.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +function getdata(url,method,data){ + return new Promise((resolve,reject)=>{ + if(!url){ + reject('url为空'); + return; + } + if(!method){ + method='POST'; + } + request({ + url: url, + method: method, + data:data + }).then((res)=>{ + resolve(res); + }).catch(ex=>{ + reject(ex); + }); + }); + +} +//档位设置 + function gearSetting(data){ + let url=""; + return getdata(url,"POST",data); +} + +//人员信息设置 +function sendUsr(data){ + let url="/app/xinghan/device/registerPersonInfo"; + return getdata(url,"POST",data); +} + +export default{ + gearSetting:gearSetting, + sendUsr:sendUsr +} + + + + + diff --git a/manifest.json b/manifest.json index f34c52a..9f1e24b 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name" : "晶全-物联", "appid" : "__UNI__A21EF43", "description" : "设备管控", - "versionName" : "1.0.8", + "versionName" : "1.0.9", "versionCode" : "100", "transformPx" : false, /* 5+App特有相关 */ diff --git a/pages.json b/pages.json index 1267e35..f2cf5b8 100644 --- a/pages.json +++ b/pages.json @@ -1,12 +1,11 @@ { "pages": [ - - { - "path": "pages/common/login/index", - "style": { - "navigationStyle": "custom" - } - }, + { + "path": "pages/common/login/index", + "style": { + "navigationStyle": "custom" + } + }, { "path" : "pages/BlueTooth/ModeSetting/index", "style" : @@ -14,6 +13,15 @@ "navigationBarTitleText" : "设备类型" } }, + { + "path" : "pages/670/HBY670", + "style" : + { + "navigationBarTitleText" : "HBY670" + } + }, + + { "path": "pages/common/index/index", "style": { @@ -200,13 +208,7 @@ "navigationBarTitleText": "呼叫" } }, - { - "path" : "pages/670/HBY670", - "style" : - { - "navigationBarTitleText" : "HBY670" - } - }, + @@ -271,7 +273,7 @@ } }, { - "path": "pages/BlueTooth/ModeSetting/HBY670", + "path": "pages/BlueTooth/ModeSetting/HBY670V1", "style": { "navigationBarTitleText": "HBY670" } diff --git a/pages/670/HBY670.vue b/pages/670/HBY670.vue index df45013..2f1551a 100644 --- a/pages/670/HBY670.vue +++ b/pages/670/HBY670.vue @@ -2,7 +2,7 @@ - + @@ -23,50 +23,89 @@ - 蓝牙名称 - {{formData.blename}} + 设备IMEI + {{device.deviceImei}} 设备名称 - {{formData.deviceName}} + {{device.deviceName}} - 预警级别 - {{formData.warnLevel}} + 定位信息 + + {{formData.lon}}  {{formData.lat}} + {{formData.address}} + + - - 警告!环境存在漏电电源! - - - - - - - + + 设备自动报警中! + {{Status.staticWarn.time}}s + + + + 档位 - + @click="GearSetting('low','staticBattery')"> 低档 + @click="GearSetting('center','staticBattery')"> 中档 + @click="GearSetting('hight','staticBattery')"> 高档 - - 关闭 + + + + SOS + + + + + + + 声光报警 + + + + + + 红蓝闪烁 - - + + 照明模式 + + + + + + + 强光 + + + + + + 弱光 + + + + + + 关闭 + + + + 人员信息登记 @@ -110,7 +149,7 @@ 姓名: - + 职位: @@ -118,7 +157,7 @@ ID号: - + @@ -168,6 +207,8 @@ import gbk from '@/utils/gbk.js' import BleTool from '@/utils/BleHelper.js' import BleReceive from '@/utils/BleReceive'; + import api from '@/api/670/HBY670.js'; + import MqttClient from '@/utils/mqtt.js'; import { showLoading, hideLoading, @@ -177,11 +218,15 @@ var ble = null; var these = null; var recei = null; + var mqttClient=null; export default { data() { return { Status: { - + staticWarn:{ + time:0, + inteval:null + }, Pop: { showPop: false, //是否显示弹窗 popType: 'custom', @@ -238,25 +283,44 @@ usrToggle: true, }, formData: { - img: '/static/images/6155/DeviceDetail/equip.png', - battary: '', - xuhang: '', - blename: '', - deviceId: '', - deviceName: '', - RSSI: '', - statu: '', - liangDu: '', - warnLevel: '', - macAddress: '', - cMode: false, - modeCurr: 'low', - - company: '黄石消防支队', - name: '菜英俊', - job: '小队长', - id: 'HSXF01061', - iswarn: false + battary: "", //电量 + xuhang: "", //续航 + imei: "", //imei + Lon: "", //经度 + Lat: "", //纬度 + address: "", //地址 + modeCurr: "", //档位 + SOS: "sg", //sos + lightCurr: "qiang", //照明模式 + company: "", //单位 + usrname: "", //姓名 + job: "", //职位 + id: "", //id + msgTxt: "", //消息1 + qzwarn: false, //是否报警 + warnLevel: "", //报警级别 + staticWarn:false,//静止报警 + fourGStrenth:0,//4G信号强度 + deviceId: "" + }, + 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/670/HBY670", + showConfirm: false }, rgb565Data: [], videoHexArray: [] @@ -268,6 +332,7 @@ ble.removeReceiveCallback(pagePath); }, onLoad: function() { + console.log("670页面加载"); these = this; recei = BleReceive.getBleReceive(); ble = BleTool.getBleTool(); @@ -278,24 +343,19 @@ console.log("收到父页面的参数:" + JSON.stringify(data)); var device = data.data; - + these.device=device; + if(these.device.deviceImei){ + these.initMQ(); + } let f = ble.data.LinkedList.find((v) => { if (v.macAddress == device.deviceMac) { console.log("找到设备了", v); - these.formData.deviceId = v.deviceId; + return true; } return false; }); if (!f) { - - - these.showPop({ - message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备", - iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", - }); return; } let form = f.formData; @@ -306,16 +366,13 @@ these.formData[key] = form[key]; } } - these.formData.blename = f.name ? f.name : "Unname"; - these.formData.deviceName = device.deviceName; - these.formData.img = device.devicePic; - these.formData.id = device.id; - these.formData.deviceId = f.deviceId; + if(these.formData['imei'] && !these.device.deviceImei){ + these.initMQ(); + } + else if(these.device.deviceImei){ + these.formData['imei'] =these.device.deviceImei; + } ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId); - these.setBleFormData(); - - - }); }, @@ -344,39 +401,86 @@ } }, methods: { - getWarnStyle(index) { - let className = ""; - switch (this.formData.warnLevel) { - case "无预警": - break; - case "弱预警": - if (index <= 1) { - className = "active"; - } - break; - case "中预警": - if (index <= 3) { - className = "active"; - } - break; - case "强预警": - if (index <= 4) { - className = "active"; - } - break; - case "非常强预警": - if (index <= 5) { - className = "active"; - } - break; - } - - return className; + initMQ() { + + return new Promise((resolve, reject) => { + console.log("正在初始化MQtt") + if (mqttClient) { + console.log("无需再次初始化") + resolve(); + return; + } + mqttClient = new MqttClient(); + mqttClient.connect(() => { + console.log("连接成功,开始订阅消息") + // 订阅来自设备的状态更新 + const statusTopic = `A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`; + mqttClient.subscribe(statusTopic, (payload, receive) => { + + try { + + let json = JSON.parse(payload); + let keys = Object.keys(json); + console.log("keys=", keys); + if (keys.indexOf('sta_DetectGrade') > -1) { //上报的报文 + console.log("收到设备上报的数据", payload); + // this.parseDataMQ(json); + } else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面 + console.log("收到开机画面答复", payload); + // this.SendImgMQ(json); + } else if (keys.indexOf('sta_TexTrans') > -1) { //发送文本信息 + console.log("收到文本回复", payload); + // this.SendTxtMQ(json); + } else if (keys.indexOf('sta_BreakNews') > -1) { //紧急通知 + console.log("收到紧急消息回复", payload); + // this.sendUrgentMQ(json); + } else { + console.log("收到不能处理的数据", payload); + } + + + } catch (error) { + console.log("无法解析此消息", error); + } + }); + resolve(); + }); + }); }, + + sendMQ(message) { + message=JSON.stringify(message); + const topic = `B/${this.formData.imei?this.formData.imei:this.device.deviceImei}`; + return new Promise((resolve, reject) => { + if (!mqttClient) { + reject("MQTT未连接"); + console.log("MQTT未连接") + return; + } + try { + let flag = mqttClient.publish(topic, message, { + qos: 1 + }); + if (flag) { + resolve(); + return; + } + console.log("MQTT未连接,无法发布消息") + reject("MQTT未连接,无法发布消息"); + } catch (error) { + console.log("出现了异常",error); + mqttClient.unsubscribe(`A/${this.formData.imei?this.formData.imei:this.device.deviceImei}`); + mqttClient.disconnect(); + this.initMQ(); + reject(error); + } + }); + }, + bleValueNotify: function(receive, device, path) { //订阅消息 let data = recei.ReceiveData(receive, device, pagePath); -console.log("收到设备的数据",data) + console.log("收到设备的数据", data) if (data) { if ("staBlue_picture" in data) { //重发图片 @@ -403,31 +507,36 @@ 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){ - these.formData[key] = data[key]; + if (key in these.formData) { + these.formData[key] = data[key]; } - } - - if (these.formData.iswarn) { + if(this.formData.imei){ + this.initMQ(); + } + if (these.formData.staticWarn) {//有静止报警 these.showPop({ - message: "环境存在漏电电源", + message: "自动报警", iconUrl: "/static/images/6155/DeviceDetail/warnning.png", borderColor: "#e034344d", buttonBgColor: "#E03434", + buttonText:"解除报警", + clickEvt:"staticWarn" }); + this.Status.staticWarn.time=180; + this.Status.staticWarn.inteval=setInterval(()=>{ + if(this.Status.staticWarn.time===0){ + clearInterval(this.Status.staticWarn.inteval); + this.formData.staticWarn=false; + return; + } + this.Status.staticWarn.time=this.Status.staticWarn.time-1; + },1000) + } these.setBleFormData(); } - - - // // 转换为字节数组 - // const bytes = receive.bytes; - // parseData(bytes); - - - }, getDevice: function() { @@ -440,7 +549,7 @@ console.log("收到设备的数据",data) return f; }, setBleFormData() { - ble.data.LinkedList.find((v) => { + let f=ble.data.LinkedList.find((v) => { if (v.deviceId == these.formData.deviceId) { v.formData = these.formData; @@ -448,110 +557,242 @@ console.log("收到设备的数据",data) } return false; }); - - uni.setStorageSync(ble.StorageKey, ble.data.LinkedList); + if(f){ + uni.setStorageSync(ble.StorageKey, ble.data.LinkedList); + } + }, - MainModeSetting: function(type, byteType) { - if (this.formData.modeCurr == type) { + lightSetting:function(type){ + if (this.formData.lightCurr == type) { return; } + + showLoading(this, { + text: "请稍候..." + }); + let task = () => { + this.formData.lightCurr = type; + let dic = { + ble: { + qiang: 0x6D, + ruo: 0x6E, + jieneng:0x6E, + close: 0x6F + }, + mqtt: { + qiang: 1, + ruo: 2, + jieneng:2, + close: 0 + } + }; + console.log("type=",type); + let json= { + ins_SOSGrade: [dic.mqtt[type]] + }; + + let requestSend=()=>{ + this.sendMQ(json).then((res)=>{ + console.log("4g发送成功"); + }).catch((ex)=>{ + these.showPop({ + message: "通信异常,请检查手机或设备网络", + iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + }); + + }).finally(()=>{ + hideLoading(these); + these.setBleFormData(); + }); + + + } + + let f = this.getDevice(); + let buffer=null; + if (f) { + // 发送数据 + buffer = new ArrayBuffer(6); + let dataView = new DataView(buffer); + dataView.setUint8(0, 0x55); // 帧头 + dataView.setUint8(1, 0x01); // 帧类型 + dataView.setUint8(2, 0x01); // 包序号 + dataView.setUint8(3, 0x00); // 数据长度 + dataView.setUint8(4, 0x01); // 数据长度 + dataView.setUint8(5, dic.ble[type]); // 数据 + + ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(() => { + console.log("蓝牙发送成功了"); + hideLoading(these); + these.setBleFormData(); + }).catch((ex) => { + //使用4G发送 + console.log("蓝牙发送失败,转4g发送",ex); + requestSend(); + }); + } else { + requestSend(); + } + } + + setTimeout(task, 0); + }, + sosSetting:function(type){ + if (this.formData.SOS == type) { + type="close"; + } + + showLoading(this, { + text: "请稍候..." + }); + let task = () => { + this.formData.SOS = type; + let dic = { + ble: { + sg: 0x68, + rb: 0x69, + close: 0x6A + }, + mqtt: { + sg: 2, + rb: 1, + close: 0 + } + + } + console.log("type=",type); + let json= { + ins_SOSGrade: [dic.mqtt[type]] + }; + + let requestSend=()=>{ + this.sendMQ(json).then((res)=>{ + console.log("4g发送成功"); + }).catch((ex)=>{ + these.showPop({ + message: "通信异常,请检查手机或设备网络", + iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + }); + + }).finally(()=>{ + hideLoading(these); + these.setBleFormData(); + }); + + + } + + let f = this.getDevice(); + let buffer=null; + if (f) { + // 发送数据 + buffer = new ArrayBuffer(6); + let dataView = new DataView(buffer); + dataView.setUint8(0, 0x55); // 帧头 + dataView.setUint8(1, 0x05); // 帧类型 + dataView.setUint8(2, 0x01); // 包序号 + dataView.setUint8(3, 0x00); // 数据长度 + dataView.setUint8(4, 0x01); // 数据长度 + dataView.setUint8(5, dic.ble[type]); // 数据 + + ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(() => { + console.log("蓝牙发送成功了"); + hideLoading(these); + these.setBleFormData(); + }).catch((ex) => { + //使用4G发送 + console.log("蓝牙发送失败,转4g发送",ex); + requestSend(); + }); + } else { + requestSend(); + } + } + + setTimeout(task, 0); + }, + GearSetting: function(type) {//档位设置 + if (this.formData.modeCurr == type) { + type="close"; + } showLoading(this, { text: "请稍候..." }); let task = () => { this.formData.modeCurr = type; - let dataValue = 0x00; - let btype = 0x00; - switch (type) { - case "low": //低档 - dataValue = 0x67; - break; - case "center": //中档 - dataValue = 0x66; - break; - case "hight": //高档 - dataValue = 0x65; - break; - case "close": //关闭 - dataValue = 0x68; - break; - case true: //开灯 - dataValue = 0x6E; - break; - case false: //关灯 - dataValue = 0x6F; - break; - default: //未知 - dataValue = 0x00; - break; + let dic = { + ble: { + hight: 0x65, + center: 0x66, + low: 0x67, + close: 0x68 + }, + mqtt: { + hight: 3, + center: 2, + low: 1, + close: 0 + } } - switch (byteType) { - case "staticBattery": - btype = 0x00; - break; - case "lamp": - btype = 0x01; - break; - default: - break; + console.log("type=",type); + let json= { + ins_DetectGrade: [dic.mqtt[type]] } - let buffer = new ArrayBuffer(6); - let dataView = new DataView(buffer); - - dataView.setUint8(0, 0x55); // 帧头 - dataView.setUint8(1, btype); // 帧类型 - dataView.setUint8(2, 0x01); // 包序号 - dataView.setUint8(3, 0x00); // 数据长度 - dataView.setUint8(4, 0x01); // 数据长度 - dataView.setUint8(5, dataValue); // 数据 - - - - let f = this.getDevice(); - - if (f) { - // 发送数据 - - ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(() => { - - - console.log("发送成功了"); - }).catch((ex) => { - + let requestSend=()=>{ + this.sendMQ(json).then((res)=>{ + console.log("4g发送成功"); + }).catch((ex)=>{ these.showPop({ - message: ex.msg, + message: "通信异常,请检查手机或设备网络", iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", borderColor: "#e034344d", buttonBgColor: "#E03434", }); - - }).finally(() => { - + + }).finally(()=>{ hideLoading(these); - these.setBleFormData(); }); - } else { - these.showPop({ - message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备", - iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", + + + } + + let f = this.getDevice(); + let buffer=null; + if (f) { + // 发送数据 + buffer = new ArrayBuffer(6); + let dataView = new DataView(buffer); + + dataView.setUint8(0, 0x55); // 帧头 + dataView.setUint8(1, 0x00); // 帧类型 + dataView.setUint8(2, 0x01); // 包序号 + dataView.setUint8(3, 0x00); // 数据长度 + dataView.setUint8(4, 0x01); // 数据长度 + dataView.setUint8(5, dic.ble[type]); // 数据 + + ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(() => { + console.log("蓝牙发送成功了"); + hideLoading(these); + these.setBleFormData(); + }).catch((ex) => { + //使用4G发送 + console.log("蓝牙发送失败,转4g发送",ex); + requestSend(); }); - hideLoading(these); + } else { + requestSend(); } } setTimeout(task, 0); - - - }, - LampToggle: function() { - - this.formData.cMode = !this.formData.cMode; - this.MainModeSetting(this.formData.cMode, "lamp"); }, + proParam: function() { uni.navigateTo({ @@ -606,11 +847,12 @@ 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); + } resolve(); @@ -635,7 +877,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); @@ -771,18 +1013,20 @@ console.log("收到设备的数据",data) this.totalPackets = totalPackets; // 发送单个数据包 const sendNextVideoPacket = () => { - console.log("准备发送一段数据"); + 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); - }); - },500); - + }).catch((ex) => { + console.log("出现异常", ex); + }); + }, 500); + } these.Status.BottomMenu.show = false; hideLoading(these); @@ -793,7 +1037,7 @@ console.log("收到设备的数据",data) }); - + resolve(); @@ -837,10 +1081,10 @@ console.log("收到设备的数据",data) } let inteval = 50; - console.log("开始发送一段视频"); // + console.log("开始发送一段视频"); // ble.sendData(f.deviceId, buffer, f.writeServiceId, f .wirteCharactId, 10).then(() => { - + updateLoading(these, { text: "正在发送:" + currentPacket + "/" + totalPackets @@ -1064,11 +1308,9 @@ console.log("收到设备的数据",data) }, HidePop: function() { - if (this.Status.Pop.clickEvt == 'SendUsr') { - + if (this.Status.Pop.clickEvt == 'staticWarn') { + this.Status.staticWarnTime=0; } - - this.Status.Pop.showPop = false; }, showPop: function(option) { @@ -1091,7 +1333,45 @@ console.log("收到设备的数据",data) }, sendUsr: function(ReSendNo) { - + let requestSend=()=>{ + let json = { + deviceId: '1942386314582163705', + deviceImei: '862419074249128', + name: this.formData.company, + position: this.formData.name, + unitName: this.formData.job, + code: this.formData.id + }; + api.sendUsr(json).then((res)=>{ + these.showPop({ + showPop: true, //是否显示弹窗 + popType: 'custom', + bgColor: '#383934bd', + borderColor: '#BBE600', + textColor: '#ffffffde', + buttonBgColor: '#BBE600', + buttonTextColor: '#232323DE', + iconUrl: '/static/images/6155/DeviceDetail/sendSucc.png', + message: '人员信息发送成功', + buttonText: '确定', + clickEvt: 'SendUsr', + visiblePrompt: false, + promptTitle: '', + modelValue: '', + visibleClose: true + }); + these.setBleFormData(); + }).catch((ex)=>{ + these.showPop({ + message: "文字发送失败," + ex.msg, + iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + }); + }).finally(()=>{ + hideLoading(these); + }); + } var textLines = [ this.formData.company, @@ -1103,12 +1383,8 @@ console.log("收到设备的数据",data) let f = this.getDevice(); if (!f) { - these.showPop({ - message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备", - iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", - }); + //走4G通道 + requestSend(); return; } showLoading(this, { @@ -1127,14 +1403,15 @@ console.log("收到设备的数据",data) // console.log("currentPacket=",currentPacket); // 发送单个数据包 const sendNextPacket = () => { - + if (currentPacket > totalPackets) { if (!ReSendNo) { - setTimeout(()=>{ - these.HoldYouHand("transmit complete", 0, f.deviceId, f.writeServiceId, f - .wirteCharactId); - },500); - + setTimeout(() => { + these.HoldYouHand("transmit complete", 0, f.deviceId, f + .writeServiceId, f + .wirteCharactId); + }, 500); + } these.showPop({ @@ -1155,6 +1432,7 @@ console.log("收到设备的数据",data) visibleClose: true }); these.setBleFormData(); + hideLoading(these); return; } @@ -1163,7 +1441,7 @@ console.log("收到设备的数据",data) let arr = gbk.encode(text) let gbkData = gbk.arr2hex(arr); - + // 构建数据包 const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分 const buffer = new ArrayBuffer(bufferSize); @@ -1174,7 +1452,7 @@ console.log("收到设备的数据",data) dataView.setUint8(1, 0x03); // 帧类型:文字 dataView.setUint8(2, currentPacket.toString(16)); // 包序号 dataView.setUint16(3, (text.length * 2).toString(16)); // 数据长度 - + // 填充数据 let index = 0; for (var i = 0; i < gbkData.length; i += 2) { @@ -1182,8 +1460,8 @@ console.log("收到设备的数据",data) dataView.setUint8(5 + index, value); index++; } - - + + // 发送数据包 @@ -1197,21 +1475,14 @@ console.log("收到设备的数据",data) currentPacket++; setTimeout(sendNextPacket, 0); }).catch(err => { - - these.showPop({ - message: "文字发送失败," + err.msg, - iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", - }); + if(err.code=='10007'){ + setTimeout(sendNextPacket, 0); + }else{ + requestSend(); + } }).finally(() => { - hideLoading(these); + }); - - - - - }; // 开始发送第一个包 @@ -1219,7 +1490,7 @@ console.log("收到设备的数据",data) } - if(ReSendNo){ + if (ReSendNo) { sendText(ReSendNo); return; } @@ -1227,17 +1498,17 @@ console.log("收到设备的数据",data) these.HoldYouHand("word transmit start", 120, f.deviceId, f.writeServiceId, f .wirteCharactId).then( () => { - setTimeout(sendText, 200); }).catch((ex) => { - console.log("握手没有成功", ex); - hideLoading(these); - these.showPop({ - message: ex.msg, - iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", - borderColor: "#e034344d", - buttonBgColor: "#E03434", - }); + requestSend(); + // console.log("握手没有成功", ex); + // hideLoading(these); + // these.showPop({ + // message: ex.msg, + // iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + // borderColor: "#e034344d", + // buttonBgColor: "#E03434", + // }); }); }, 0); @@ -1268,6 +1539,7 @@ console.log("收到设备的数据",data) resolve(true); }, pauseTime); }).catch(err => { + console.log("握手没有成功", ) reject(err); }); @@ -1684,17 +1956,20 @@ console.log("收到设备的数据",data) align-content: center; justify-content: space-around; align-items: center; - + border-radius: 8px; + background: rgba(26, 26, 26, 1); + box-sizing: border-box; + padding: 30rpx 0rpx; } .modeSetting .item { - width: 150rpx; - height: 150rpx; - background: rgba(26, 26, 26, 1); + width: 120rpx; + height: 120rpx; + background: rgba(42, 42, 42, 1); border-radius: 50%; color: rgba(255, 255, 255, 0.87); - margin-top: 20rpx; + font-family: PingFang SC; font-size: 28rpx; font-weight: 400; @@ -1800,42 +2075,118 @@ console.log("收到设备的数据",data) align-items: center; } - .netContent { + .optTitle{ + color: rgba(255, 255, 255, 0.87); + +font-family: 'PingFang SC'; +font-size: 28rpx; +font-weight: 400; + +letter-spacing: 0.14rpx; +text-align: left; +width: 100%; +box-sizing: border-box; +padding:30rpx 0rpx 10rpx 30rpx; + } + + .sosContent{ + width: 100%; + height: 130rpx; + display: flex; flex-direction: row; flex-wrap: nowrap; - align-content: flex-end; - justify-content: space-around; - align-items: flex-end; - width: 50rpx; + align-content: center; + justify-content: space-between; + align-items: center; + } + .sosContent .item{ + width:calc(calc(100% - 80rpx) / 2); + height: 100%; + box-sizing: border-box; + border-radius: 16rpx; + background: rgba(26, 26, 26, 1); + color: rgba(255, 255, 255, 0.87); + font-family: 'PingFang SC'; + font-size: 28rpx; + font-weight: 400; + letter-spacing: 0.14rpx; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-content: center; + justify-content: center; + align-items: center; } - .net { - width: 7rpx; - background: rgba(255, 255, 255, 0.3); + .sosContent .item.active{ + border: 1px solid rgba(224, 52, 52, 1); + color: rgba(224, 52, 52, 1); } - .net.netone { - height: 11rpx; + .sosContent .imgContent{ + width: 55rpx; + height: 55rpx; + background-color: #232323; + border-radius: 4rpx; + margin-right: 30rpx; + } + .sosContent .imgContent .img{ + width: 70%; + height: 70%; + } - .net.nettwo { - height: 17rpx; + .sosContent .item.active .imgContent{ + background-color: #E034340F; } - .net.netsiri { - height: 23rpx; + .lightMode{ + width: 100%; + height: 180rpx; + border-radius: 16rpx; +background: rgba(26, 26, 26, 1); +margin-bottom: 30rpx; +display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-content: center; + justify-content: space-between; + align-items: center; } - .net.netfour { - height: 29rpx; + + .lightMode .item{ + width:calc(calc(100% - 90rpx) / 3); + height: 100%; + box-sizing: border-box; + border-radius: 16rpx; + + color: rgba(255, 255, 255, 0.87); + font-family: 'PingFang SC'; + font-size: 28rpx; + font-weight: 400; + letter-spacing: 0.14rpx; + display: flex; + flex-direction: column; + flex-wrap: nowrap; + align-content: center; + justify-content: space-evenly; + align-items: center; } - .net.netfive { - height: 35rpx; + .lightMode .item.active{ + + color:#AED600; } - .net.active { - background: #FFFFFF !important; + .lightMode .imgContent{ + width: 80rpx; + height: 100rpx; + } + .lightMode .imgContent .img{ + width: 100%; + height: 100%; + } \ No newline at end of file diff --git a/pages/BlueTooth/ModeSetting/HBY670.vue b/pages/BlueTooth/ModeSetting/HBY670V1.vue similarity index 100% rename from pages/BlueTooth/ModeSetting/HBY670.vue rename to pages/BlueTooth/ModeSetting/HBY670V1.vue diff --git a/pages/BlueTooth/ModeSetting/VideoSend_670.vue b/pages/BlueTooth/ModeSetting/VideoSend_670.vue index 1e26ab4..1e8bc89 100644 --- a/pages/BlueTooth/ModeSetting/VideoSend_670.vue +++ b/pages/BlueTooth/ModeSetting/VideoSend_670.vue @@ -59,7 +59,7 @@ var mqttClient=null; videoDuration: 2, hexArray: [], -reSendNumber:"" + reSendNumber:"" } }, onLoad() { @@ -401,7 +401,7 @@ reSendNumber:"" }).catch(err => { console.log("完成指令发送失败"); }); - },500) + },1500) }, sendData(buffer) { diff --git a/pages/BlueTooth/ModeSetting/index.vue b/pages/BlueTooth/ModeSetting/index.vue index 88dc2cb..d0edfba 100644 --- a/pages/BlueTooth/ModeSetting/index.vue +++ b/pages/BlueTooth/ModeSetting/index.vue @@ -33,7 +33,7 @@ url: '6155_V1' }, { - name: "/pages/BlueTooth/ModeSetting/HBY670", + name: "/pages/BlueTooth/ModeSetting/HBY670V1", url: 'HBY670' }, diff --git a/pages/common/login/index.vue b/pages/common/login/index.vue index f4dd3a8..ec2e5ec 100644 --- a/pages/common/login/index.vue +++ b/pages/common/login/index.vue @@ -69,6 +69,29 @@ showAgreement: false, // 控制弹窗显示 } }, + onLoad(){ + if(uni.getStorageSync("token") && uni.getStorageSync("clientID")){//免登陆 + + let time=uni.getStorageSync("tokenTime"); + if(!time){ + time=0; + } + let currTime=new Date().getTime(); + if(currTime { console.log("蓝牙初始化成功:" + JSON.stringify(args)); this.data.isOpenBlue = true; + this.data.available=true; resolve(true); if (this.data.isSubscribe) { //整个App生命周期,只订阅一次 @@ -939,6 +940,10 @@ class BleHelper { resolve(false); return; } + if(!this.data.available){ + reject(this.getError({code:10001})); + return; + } console.log("正在连接" + deviceId); uni.createBLEConnection({ deviceId: deviceId, diff --git a/utils/BleReceive.js b/utils/BleReceive.js index ad07427..13a0b99 100644 --- a/utils/BleReceive.js +++ b/utils/BleReceive.js @@ -257,25 +257,25 @@ class BleReceive { try { // 跳过帧头(第一个字节),从第二个字节开始解析 let staticLevelByte = bytes[1]; - let staticLevelText = '未知'; + let staticLevelText = ''; switch (staticLevelByte) { case 0x65: - staticLevelText = '高档'; + staticLevelText = 'hight'; break case 0x66: - staticLevelText = '中档'; + staticLevelText = 'center'; break case 0x67: - staticLevelText = '低档'; + staticLevelText = 'low'; break case 0x68: - staticLevelText = '关闭'; + staticLevelText = 'close'; break } // 解析照明档位 let lightingLevelByte = bytes[2]; - let lightingLevelText = lightingLevelByte === 0x6d ? '强光': lightingLevelByte === 0x6e ? '弱光': '关闭'; + let lightingLevelText = lightingLevelByte === 0x6d ? 'hight': lightingLevelByte === 0x6e ? 'low': 'close'; // 解析剩余照明时间(第三和第四字节,小端序) let lightingTime = (bytes[3] << 8) | bytes[4]; @@ -286,26 +286,26 @@ class BleReceive { let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte)); let warn = bytes[6]; - if (warn == 0x00) { - warn = '无预警'; - } else if (warn == 0x01) { - warn = '弱预警'; - } else if (warn == 0x02) { - warn = '中预警'; - } else if (warn == 0x03) { - warn = '强预警'; - } else if (warn == 0x04) { - warn = '非常强预警'; - } + // if (warn == 0x00) { + // warn = '无预警'; + // } else if (warn == 0x01) { + // warn = '弱预警'; + // } else if (warn == 0x02) { + // warn = '中预警'; + // } else if (warn == 0x03) { + // warn = '强预警'; + // } else if (warn == 0x04) { + // warn = '非常强预警'; + // } - let staticWarn = bytes[7] == 0x01 ? '静止报警': '无静止报警'; + let staticWarn = bytes[7] == 0x01;//静止报警 let fourGStrenth = bytes[8]; //4g信号强度 - let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? '爆闪模式' : '红蓝模式'; + let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? 'sg' : 'rb'; - receiveData.staticLevel = staticLevelText; - receiveData.lightingLevel = lightingLevelText; - receiveData.lightingTime = lightingTime ; - receiveData.batteryLevel = batteryLevel; + receiveData.modeCurr = staticLevelText; + receiveData.lightCurr = lightingLevelText; + receiveData.xuhang = lightingTime ; + receiveData.battary = batteryLevel; receiveData.warnLevel = warn; receiveData.staticWarn = staticWarn; receiveData.fourGStrenth = fourGStrenth;