我的流程是没问题的,如下: // 第一步初始化蓝牙适配器 wx.openBluetoothAdapter({ success: function(res) { console.log("初始化蓝牙适配器成功") }, fail: function(err) { //在用户蓝牙开关未开启或者手机不支持蓝牙功能的情况下,调用 wx.openBluetoothAdapter 会返回错误(errCode=10001),表示手机蓝牙功能不可用 } }) // 同时监听蓝牙适配器状态变化事件 wx.onBluetoothAdapterStateChange(res => { }) // 第二步开始扫描蓝牙 wx.onBluetoothDeviceFound((devices) => {}) //扫描附近的外围设备 wx.startBluetoothDevicesDiscovery({ powerLevel: "high", complete(res) { console.log('startBluetoothDevicesDiscovery ----', res) } }); if (timeOut != null) { console.log('有扫描任务在进行 先清除任务') clearTimeout(timeOut) }
华为Mate20 - 无法使用低功耗蓝牙的问题,请求解答//扫描附近的外围设备 wx.startBluetoothDevicesDiscovery({ powerLevel: "high", complete(res) { console.log('startBluetoothDevicesDiscovery ----', res) } }); [图片] 用其他测试手机(iPhone、小米、360)均没有发现此问题,就华为Mate20手机搜索不到设备,控制台的信息如上图; 微信版本:7.0.12 基础运行库:2.10.3 运行系统:29 微信号:dong514745,日志上传时间 2020-03-19 16:35,上传完成时间:2020-03-19 16:42 麻烦管理员看看这个问题
2020-03-20有没有人来帮帮我啊,手动捂脸。
oppo r17链接不上蓝牙,错误10012手机能发现蓝牙,但是链接基本都是失败的,如下图 [图片] 但是我用360,小米,华为,iphone6,7,x都没有问题 已上传日志,微信号:wxid_izcm8mgimxl922,时间:2019年9月4号18点09分左右 求解答
2019-09-05问题已解决
wx.onBLECharacteristicValueChange 在安卓无回调help,wx.onBLECharacteristicValueChange 在android上无法接受返回值,notify开启是成功的,有趣的是在iOS下面一切正常,问了好多人,又说开启notify之后立即就调用了write会发生问题,尝试了延迟和重发依旧没有任何返回值,下图是测试返回的结果 ···························································································································· [图片] 上图是在ios设备的截图,能接收到返回值 ·································································································· [图片] 这实在android设备的,没有返回值 ··································································································· - 求问技术支持,这问题该如何解决,是否有解决方案,下面贴出我的代码,帮忙看看是不是我写的有问题 [代码]Page({[代码] [代码] [代码][代码]/** 页面的初始数据 */[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]deviceId: [代码][代码]'FD:76:74:35:99:92'[代码][代码],[代码][代码] [代码][代码]serviceId: [代码][代码]''[代码][代码],[代码][代码] [代码][代码]services: [],[代码][代码] [代码][代码]writeCharacteristicsId: [代码][代码]""[代码][代码], [代码][代码]// 可写特征值uuid[代码][代码] [代码][代码]readCharacteristicsId: [代码][代码]""[代码][代码], [代码][代码]// 可读特征值uuid[代码][代码] [代码][代码]notifyCharacteristicsId: [代码][代码]""[代码][代码], [代码][代码]// 通知特征值uuid[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]/** 生命周期函数--监听页面加载 */[代码][代码] [代码][代码]onLoad: [代码][代码]function[代码] [代码](opt) {[代码][代码] [代码][代码]//初始化蓝牙适配器[代码][代码] [代码][代码]wx.openBluetoothAdapter({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]"初始化蓝牙适配器成功"[代码][代码], res);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](err) {[代码][代码] [代码][代码]console.log([代码][代码]"初始化失败"[代码][代码], err)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]//监听蓝牙适配器状态变化事件[代码][代码] [代码][代码]wx.onBluetoothAdapterStateChange(res => {[代码][代码] [代码][代码]console.log([代码][代码]"状态变化"[代码][代码], res)[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]start: [代码][代码]function[代码][代码]() {[代码][代码] [代码][代码]let that = [代码][代码]this[代码][代码];[代码] [代码] [代码][代码]console.log([代码][代码]'监听设备的连接状态'[代码][代码]);[代码] [代码] [代码][代码]/** 连接设备 */[代码][代码] [代码][代码]wx.createBLEConnection({[代码][代码] [代码][代码]deviceId: that.data.deviceId,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'连接设备'[代码][代码], res);[代码] [代码] [代码][代码]/** 监听设备的连接状态 */[代码][代码] [代码][代码]wx.onBLEConnectionStateChanged([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)[代码][代码] [代码][代码]});[代码] [代码] [代码][代码]/** 连接成功,后开始获取设备的服务列表 */[代码][代码] [代码][代码]wx.getBLEDeviceServices({[代码][代码] [代码][代码]deviceId: that.data.deviceId,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'device services:'[代码][代码], res);[代码] [代码] [代码][代码]that.setData({ services: res.services, serviceId: res.services[0].uuid }, () => {[代码] [代码] [代码][代码]wx.getBLEDeviceCharacteristics({[代码][代码] [代码][代码]deviceId: that.data.deviceId,[代码][代码] [代码][代码]serviceId: that.data.serviceId,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'device getBLEDeviceCharacteristics:'[代码][代码], res.characteristics);[代码] [代码] [代码][代码]for[代码] [代码]([代码][代码]var[代码] [代码]i = 0; i < res.characteristics.length; i++) {[代码][代码] [代码][代码]if[代码] [代码](res.characteristics[i].properties.notify) {[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]notifyCharacteristicsId: res.characteristics[i].uuid[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]if[代码] [代码](res.characteristics[i].properties.write) {[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]writeCharacteristicsId: res.characteristics[i].uuid[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]if[代码] [代码](res.characteristics[i].properties.read) {[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]readCharacteristicsId: res.characteristics[i].uuid[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]/** 顺序开发设备特征notifiy */[代码][代码] [代码][代码]wx.notifyBLECharacteristicValueChanged({[代码][代码] [代码][代码]deviceId: that.data.deviceId,[代码][代码] [代码][代码]serviceId: that.data.serviceId,[代码][代码] [代码][代码]characteristicId: that.data.notifyCharacteristicsId,[代码][代码] [代码][代码]state: [代码][代码]true[代码][代码],[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'notifyBLECharacteristicValueChanged success'[代码][代码], res);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](res) { console.log([代码][代码]'notifyBLECharacteristicValueChanged fail :'[代码][代码], res) },[代码][代码] [代码][代码]complete: [代码][代码]function[代码] [代码](res) { }[代码][代码] [代码][代码]});[代码] [代码] [代码][代码]/** 回调获取 设备发过来的数据 */[代码][代码] [代码][代码]wx.onBLECharacteristicValueChange([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'characteristic value comed:'[代码][代码], res.value);[代码][代码] [代码][代码]//{value: ArrayBuffer, deviceId: "D8:00:D2:4F:24:17", serviceId: "ba11f08c-5f14-0b0d-1080-007cbe238851-0x600000460240", characteristicId: "0000cd04-0000-1000-8000-00805f9b34fb-0x60800069fb80"}[代码] [代码] [代码][代码]let buffer = res.value[代码][代码] [代码][代码]let dataView = [代码][代码]new[代码] [代码]DataView(buffer)[代码][代码] [代码][代码]let dataResult = [][代码][代码] [代码][代码]for[代码] [代码](let i = 0; i < dataView.byteLength; i++) {[代码][代码] [代码][代码]dataResult.push(dataView.getUint8(i).toString(16))[代码][代码] [代码][代码]}[代码][代码] [代码][代码]const result = dataResult[代码][代码] [代码][代码]console.log(result);[代码][代码] [代码][代码]});[代码] [代码] [代码][代码]/** 发送开锁命令 */[代码][代码] [代码][代码]that.send();[代码] [代码] [代码][代码]}, fail: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'失败'[代码][代码], res);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]/** 发送 数据到设备中 */[代码][代码] [代码][代码]send: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]let that = [代码][代码]this[代码][代码], hex = [代码][代码]'100031B0000018FFFFFFFF0000008900'[代码][代码];[代码][代码] [代码][代码]const typedArray = [代码][代码]new[代码] [代码]Uint8Array(hex.match(/[\da-f]{2}/gi).map([代码][代码]function[代码] [代码](h) { [代码][代码]return[代码] [代码]parseInt(h, 16) }))[代码][代码] [代码][代码]console.log(typedArray);[代码][代码] [代码][代码]const buffer1 = typedArray.buffer[代码][代码] [代码][代码]console.log(buffer1)[代码] [代码] [代码][代码]wx.writeBLECharacteristicValue({[代码][代码] [代码][代码]deviceId: that.data.deviceId,[代码][代码] [代码][代码]serviceId: that.data.serviceId,[代码][代码] [代码][代码]characteristicId: that.data.writeCharacteristicsId,[代码][代码] [代码][代码]value: buffer1,[代码] [代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]"success 指令发送成功"[代码][代码]);[代码][代码] [代码][代码]console.log(res);[代码] [代码] [代码][代码]/** 读取设备 */[代码][代码] [代码][代码]// setTimeout(() => {[代码][代码] [代码][代码]// wx.readBLECharacteristicValue({[代码][代码] [代码][代码]// deviceId: that.data.deviceId,[代码][代码] [代码][代码]// serviceId: that.data.serviceId,[代码][代码] [代码][代码]// characteristicId: that.data.readCharacteristicsId,[代码][代码] [代码][代码]// success: function (res) {[代码][代码] [代码][代码]// console.log('readBLECharacteristicValue:', res);[代码][代码] [代码][代码]// }[代码][代码] [代码][代码]// })[代码][代码] [代码][代码]// }, 3000)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](res) { console.log(res); }[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]/** 生命周期函数--监听页面初次渲染完成 */[代码][代码] [代码][代码]onReady: [代码][代码]function[代码] [代码]() { },[代码] [代码] [代码][代码]/** 生命周期函数--监听页面显示 */[代码][代码] [代码][代码]onShow: [代码][代码]function[代码] [代码]() { },[代码] [代码] [代码][代码]/** 生命周期函数--监听页面隐藏 */[代码][代码] [代码][代码]onHide: [代码][代码]function[代码] [代码]() { },[代码] [代码] [代码][代码]/** 生命周期函数--监听页面卸载, 同时断开蓝牙 */[代码][代码] [代码][代码]onUnload: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]let me = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.closeBLEConnection({[代码][代码] [代码][代码]deviceId: me.data.deviceId,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]"蓝牙断开"[代码][代码], res)[代码][代码] [代码][代码]me.setData({ deviceId: [代码][代码]""[代码][代码], })[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码] [代码]})[代码] 在线等。
2019-01-09