我们这边是让同事开发了一个可以用蓝牙连接的硬件设备,
硬件蓝牙设备的版本是:
蓝牙 V4.2 BR/EDR,
低功耗蓝牙
然后我这边使用的是官方文档蓝牙扫描相关的API,但是没有扫描到设备,所以问一下怎么回事
async initBT() {
let allList = [];
this.btLoading = true
//开启蓝牙模块
console.log('openBlue');
await wx.openBluetoothAdapter({
fail:(err=>{
console.log('openBlue',err);
wx.showToast({
icon:'error',
title:'请开启蓝牙',
})
})
})
console.log('bluetoothAdapterState',bluetoothAdapterState);
console.log('startScan');
await wx.startBluetoothDevicesDiscovery({
fail:(err=>{
console.log('startScan',err);
wx.showToast({
icon:'error',
title:'扫描蓝牙失败',
})
})
})
//获取蓝牙适配器状态
let bluetoothAdapterState = await wx.getBluetoothAdapterState()
console.log('bluetoothAdapterState',bluetoothAdapterState);
// 不在搜索中
if (bluetoothAdapterState['discovering']) {
console.log('scanning');
wx.onBluetoothDeviceFound(res => {
allList = [res.devices,...allList];
allList.forEach(resItem=>{
resItem.forEach(item=>{
if(item.connectable){
const device = item;
const name = device.name || ''
const localName = device.localName || ''
const deviceId = device.deviceId
const mac = wx.ab2hex(device.advertisData)
if (this.deviceList.findIndex(e => e.deviceId === deviceId) === -1) {
this.deviceList.push({
mac: mac,
name: name,
localName: localName,
deviceId: deviceId,
advertisData: this.ab2hex(device.advertisData).substring(0, 16)
})
}
}
})
})
})
}
setTimeout(async ()=>{
console.log('deviceList',this.deviceList);
wx.getBluetoothDevices({
success:(res)=>{
console.log('allRes',res)
res.devices.forEach(item=>{
if(item.connectable){
console.log('item',item)
}
})
}
});
await wx.stopBluetoothDevicesDiscovery()
this.btLoading = false
},5000)
},
你好,确认下设备是不是BLE设备
我也搜索不到一个蓝牙4.0的一个条码打印机。