fix:修改蓝牙
This commit is contained in:
parent
2fe3f68e2a
commit
1165735a11
@ -162,7 +162,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted ,reactive } from 'vue';
|
||||
import { ref, onMounted ,reactive, onBeforeUnmount } from 'vue';
|
||||
import {
|
||||
showModelMessage
|
||||
} from '@/utils/tools.js';
|
||||
@ -230,6 +230,7 @@
|
||||
success(res) {
|
||||
if(res.errno == 0){
|
||||
blueTooth.value.blueConn = true;
|
||||
blueTooth.value.bikeCode = '250306001002'
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -256,6 +257,24 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// 页面卸载时关闭蓝牙连接
|
||||
if(blueTooth.value.deviceId != ""){
|
||||
closeConn();
|
||||
}
|
||||
// 停止蓝牙设备搜索
|
||||
stopBluetoothDevicesDiscovery();
|
||||
// 关闭蓝牙适配器
|
||||
uni.closeBluetoothAdapter({
|
||||
success(res) {
|
||||
console.log("closeBluetoothAdapter success", res);
|
||||
},
|
||||
fail(err) {
|
||||
console.log("closeBluetoothAdapter err", err);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
let timer;
|
||||
const bikeCodeScanChange = (data) => {
|
||||
@ -445,8 +464,10 @@
|
||||
console.log('蓝牙服务:', res.services);
|
||||
for (var i = 0; i < res.services.length; i++) {
|
||||
var serviceId = res.services[i].uuid;
|
||||
var subServiceId = serviceId.value.substring(0, 8);
|
||||
var subServiceId = serviceId.substring(0, 8);
|
||||
if (subServiceId == '0000fff0' || subServiceId == '0000FFF0' || subServiceId == '6e400001' || subServiceId == '6E400001') {
|
||||
console.log('符合的subServiceId =' + subServiceId);
|
||||
|
||||
ids.serviceId = serviceId;
|
||||
//获取蓝牙设备某个服务中所有特征值(characteristic)。
|
||||
uni.getBLEDeviceCharacteristics({
|
||||
@ -460,10 +481,13 @@
|
||||
var subCharacteristic = characteristicId.substring(0, 8);
|
||||
//读
|
||||
if (subCharacteristic == '0000fff6' || subCharacteristic == '0000FFF6' || subCharacteristic == '6e400003' || subCharacteristic == '6E400003') {
|
||||
console.log('characteristicId =' + characteristicId);
|
||||
ids.characteristicId = characteristicId;
|
||||
}
|
||||
//写
|
||||
else if (subCharacteristic == '6e400002' || subCharacteristic == '6E400002') {
|
||||
console.log('writeCharacteristicId =' + characteristicId);
|
||||
|
||||
ids.writeCharacteristicId = characteristicId;
|
||||
}
|
||||
}
|
||||
@ -482,11 +506,12 @@
|
||||
fail: function (res) {
|
||||
console.log('获取服务失败');
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const startNotify = () => {
|
||||
console.log('ids----------',ids);
|
||||
uni.notifyBLECharacteristicValueChange({
|
||||
state:true,
|
||||
deviceId: blueTooth.value.deviceId,
|
||||
@ -564,6 +589,9 @@
|
||||
}
|
||||
|
||||
const writeBLECharacteristicValueWithBuff = (buffer) => {
|
||||
console.log('执行的命令--------',buffer);
|
||||
console.log('characteristicId:' + ids.writeCharacteristicId);
|
||||
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: blueTooth.value.deviceId,
|
||||
serviceId: ids.serviceId,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user