小程序蓝牙API搜索不到蓝牙设备
- 使用小程序蓝牙文档中的示例程序,运行之后搜索不到蓝牙设备
- 首页头像点进去,点击开始搜索,搜索不到附近已开启的蓝牙设备
8 回复
你好,请确认已经开启手机蓝牙,另外麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
全是未知设备很操蛋啊…什么都搜不到…蓝牙耳机,电脑,手机…
onLoad: function (){}, taponce: function (){ var deviceId; var i = 0; var serviceId = []; var characteristicId = []; wx.openBluetoothAdapter({ success: function (res) { console.log(res, "success" ); wx.startBluetoothDevicesDiscovery({ services: [], success: function (res) { console.log(res) }, fail: function (res) { console.log( "fail" ) }, }) }, fail: function (res) { console.log( "fail" ) }, }), wx.getBluetoothDevices({ success: function (res) { console.log( "getBluetoothDevices" ,res) i = 0; while (res.devices[i]) { console.log( "i" ,i); console.log(res.devices[i].name, res.devices[i].deviceId); if (res.devices[i].name == 'YahBoom_BL' ) { deviceId = res.devices[i].deviceId; console.log(deviceId); } i++; } } }), wx.getBLEDeviceServices({ deviceId: deviceId, success: function (res) { console.log( "getBLEDeviceServices.services" ,res.services); i = 0; while (res.services[i]) { serviceId[i] = res.services[i].uuid; console.log(serviceId[i]); i++; } }, }), wx.getBLEDeviceCharacteristics({ deviceId: deviceId, serviceId: serviceId[1], success: function (res) { i = 0; while (res.characteristics[i]) { characteristicId[i] = res.characteristics[i].uuid; console.log(characteristicId[i]); i++; } } }) |