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