蓝牙连接失败 基于微信6.6.7 华为mate10 Android8.0 系统
- 当前问题的表现 已搜索到蓝牙设备的mac地址,通过wx.createBLEConnection连接该设备,要么连接失败,或者连接成功后但无法写特征值。 调试信息如下: (16) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]0: {deviceId: "88:83:5D:56:CD:F1", name: "V1 Plus", RSSI: -61, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}1: {deviceId: "88:83:5D:56:C8:B0", name: "V7c", RSSI: -50, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}2: {deviceId: "88:83:5D:56:2D:37", name: "V1 Plus", RSSI: -85, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}3: {deviceId: "88:83:5D:56:73:D4", name: "YX-PR-01A", RSSI: -78, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}4: {deviceId: "88:83:5D:56:CB:94", name: "QQ亲戚", RSSI: -61, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}5: {deviceId: "88:83:5D:57:13:F6", name: "V1 Plus", RSSI: -85, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}6: {deviceId: "88:83:5D:56:77:58", name: "V1 Plus", RSSI: -67, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}7: {deviceId: "88:83:5D:56:2D:6D", name: "V1 Plus", RSSI: -64, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}8: {deviceId: "88:83:5D:56:2D:4D", name: "V1 Plus", RSSI: -68, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}9: {deviceId: "88:83:5D:56:C8:C9", name: "厨房", RSSI: -37, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}10: {deviceId: "88:83:5D:57:19:E7", name: "V1 Plus", RSSI: -65, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}11: {deviceId: "88:83:5D:56:CA:13", name: "V1 Plus", RSSI: -88, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}12: {deviceId: "88:83:5D:56:30:41", name: "V1 Plus", RSSI: -89, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}13: {deviceId: "88:83:5D:56:C4:F7", name: "卧室", RSSI: -62, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}14: {deviceId: "88:83:5D:57:16:C7", name: "家庭活动室", RSSI: -79, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}15: {deviceId: "88:83:5D:56:73:B0", name: "rrww", RSSI: -56, advertisData: ArrayBuffer, advertisServiceUUIDs: Array(0), …}length: 16__proto__: Array(0) index.js? [sm]:460 stop index.js? [sm]:460 stop index.js? [sm]:460 stop index.js? [sm]:505 deviceId 88:83:5D:56:C8:C9 index.js? [sm]:566 连接失败 {errCode: 10012, errMsg: "createBLEConnection:fail:operate time out"} fail @ index.js? [sm]:566 (anonymous) @ [publib]:3 (anonymous) @ [publib]:4 b @ [publib]:1 handleCallInterfaceResult @ [publib]:543 handleProcessMessage @ [publib]:782 ws.on @ [publib]:894 emitOne @ events.js:115 emit @ events.js:210 _receiver.onmessage @ C:\Program Files (x86)\Tencent\微信web开发者工具\package.nw\node_modules\ws\lib\WebSocket.js:141 dataMessage @ C:\Program Files (x86)\Tencent\微信web开发者工具\package.nw\node_modules\ws\lib\Receiver.js:389 getData @ C:\Program Files (x86)\Tencent\微信web开发者工具\package.nw\node_modules\ws\lib\Receiver.js:330 startLoop @ C:\Program Files (x86)\Tencent\微信web开发者工具\package.nw\node_modules\ws\lib\Receiver.js:165 add @ C:\Program Files (x86)\Tencent\微信web开发者工具\package.nw\node_modules\ws\lib\Receiver.js:139 _ultron.on @ C:\Program Files (x86)\Tencent\微信web开发者工具\package.nw\node_modules\ws\lib\WebSocket.js:138 emitOne @ events.js:115 emit @ events.js:210 addChunk @ _stream_readable.js:263 readableAddChunk @ _stream_readable.js:250 Readable.push @ _stream_readable.js:208 onread @ net.js:595 index.js? [sm]:460 stop index.js? [sm]:505 deviceId 88:83:5D:56:C8:C9 index.js? [sm]:525 连接成功 {errCode: 0, errMsg: "createBLEConnection:ok"} index.js? [sm]:460 stop index.js? [sm]:170 obj {top: false, bottom: true, left: false, right: false, startTime: 1530013063376, …} index.js? [sm]:598 写入内存时间 1530013063388 bottompress press index.js? [sm]:630 发送 1530013063388 index.js? [sm]:181 end {top: false, bottom: false, left: false, right: false, isTouch: false, …} index.js? [sm]:598 写入内存时间 1530013063516 bottompop pop index.js? [sm]:598 写入内存时间 1530013063540 bottompop pop index.js? [sm]:630 发送 1530013063641 writeDeviceCharacter.js? [sm]:19 用时 261 {errCode: 10004, errMsg: "writeBLECharacteristicValue:fail:no service"} press writeDeviceCharacter.js? [sm]:19 用时 182 {errCode: 10004, errMsg: "writeBLECharacteristicValue:fail:no service"} pop 使用IOS测试无任何问题,使用低版本的Android6.0手机也没有问题。 请参考具体的建立连接代码片段如下: wx.createBLEConnection({ deviceId: deviceId, // mainThread: false, // needDiscoryService: true, success: function (res) { // wx.hideToast(); console.log('连接成功', res) if (that.data.ios){ //从连接中获取serviceUUid与characterUUid 苹果机限制必须先获取才能使用 getDeviceService.call(that); } else { that.setData({ tip: `当前连接设备: ${deviceName}`, isConnected: true, isModal: false, selectDevice: '' }) wx.showToast({ title: '连接成功', }) that.closeModal(); that.selfData.connecting = false } 不知是我代码调用有问题,还是手机有何设置未开启 请遇到类似问题的朋友方便的话帮忙答复一下,谢谢!