最近开发小程序蓝牙碰到很多问题,第一是蓝牙下发一包数据很慢,两秒一包,所以我想单纯的测试一下蓝牙下载速度,于是在官方demo基础是做了一个蓝牙下载的测试,期间升级了开发工具,之后频繁出现10004错误代码,偶尔才能成功下载一次。望课代表予以解答。在线等,急
getBLEDeviceServices "errCode":10004- 当前 Bug 的表现(可附上截图) 小米9 真机调试蓝牙 总出现10004 code ,不知道原因,偶尔不会出现 14:16:40.702 index.js:40 openBluetoothAdapter success {errMsg: "openBluetoothAdapter:ok"} 14:16:40.913 index.js:75 startBluetoothDevicesDiscovery success {errCode: 0, errMsg: "startBluetoothDevicesDiscovery:ok", isDiscovering: true} 14:16:43.572 index.js:115 createBLEConnection success {"errCode":0,"errMsg":"createBLEConnection:ok"} 14:16:44.005 index.js:152 getBLEDeviceServices 34:03:DE:58:7C:3D fail {"errCode":10004,"errMsg":"getBLEDeviceServices:fail:no service"} - 预期表现 - 复现路径 - 提供一个最简复现 Demo 官方蓝牙demo修改的 openBluetoothAdapter() { wx.openBluetoothAdapter({ success: (res) => { console.log('openBluetoothAdapter success', res) this.startBluetoothDevicesDiscovery() }, fail: (res) => { if (res.errCode === 10001) { wx.onBluetoothAdapterStateChange(function (res) { console.log('onBluetoothAdapterStateChange', res) if (res.available) { this.startBluetoothDevicesDiscovery() } }) } } }) }, getBluetoothAdapterState() { wx.getBluetoothAdapterState({ success: (res) => { console.log('getBluetoothAdapterState', res) if (res.discovering) { this.onBluetoothDeviceFound() } else if (res.available) { this.startBluetoothDevicesDiscovery() } } }) }, startBluetoothDevicesDiscovery() { if (this._discoveryStarted) { return } this._discoveryStarted = true wx.startBluetoothDevicesDiscovery({ allowDuplicatesKey: true, success: (res) => { console.log('startBluetoothDevicesDiscovery success', res) this.onBluetoothDeviceFound() }, }) }, stopBluetoothDevicesDiscovery() { wx.stopBluetoothDevicesDiscovery() }, onBluetoothDeviceFound() { wx.onBluetoothDeviceFound((res) => { res.devices.forEach(device => { if (!device.name && !device.localName) { return } const foundDevices = this.data.devices const idx = inArray(foundDevices, 'deviceId', device.deviceId) const data = {} if (idx === -1) { data[`devices[${foundDevices.length}]`] = device } else { data[`devices[${idx}]`] = device } this.setData(data) }) }) }, onBLEConnectionStateChange(){ wx.onBLEConnectionStateChange(function (res) { // 该方法回调中可以用于处理连接意外断开等异常情况 console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`) }) }, createBLEConnection(e) { var that = this const ds = e.currentTarget.dataset const deviceId = ds.deviceId const name = ds.name wx.createBLEConnection({ deviceId, success: (res) => { console.log('createBLEConnection success', JSON.stringify(res)) this.setData({ connected: true, name, deviceId, }) //this.getBLEDeviceServices(deviceId) setTimeout(function () { that.getBLEDeviceServices(deviceId) }, 300) setInterval(function () { that.onBLEConnectionStateChange()},5000) } }) this.stopBluetoothDevicesDiscovery() }, closeBLEConnection() { wx.closeBLEConnection({ deviceId: this.data.deviceId }) this.setData({ connected: false, chs: [], canWrite: false, }) }, getBLEDeviceServices(deviceId) { var that =this wx.getBLEDeviceServices({ deviceId, success: (res) => { console.log('getBLEDeviceServices ' + deviceId+ ' success', JSON.stringify(res)) for (let i = 0; i < res.services.length; i++) { if (res.services[i].isPrimary && res.services[i].uuid.indexOf("0000FFF0") != -1) { this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid) } } }, fail:(res)=>{ console.log('getBLEDeviceServices ' + deviceId + ' fail', JSON.stringify(res)) //setTimeout(function () { that.getBLEDeviceServices(deviceId)} , 3000 ) } }) }, getBLEDeviceCharacteristics(deviceId, serviceId) { wx.getBLEDeviceCharacteristics({ deviceId, serviceId, success: (res) => { console.log('getBLEDeviceCharacteristics2 success', JSON.stringify(res)) //console.log('getBLEDeviceCharacteristics1 success', res.characteristics) for (let i = 0; i < res.characteristics.length; i++) { let item = res.characteristics[i] if (item.properties.read) { wx.readBLECharacteristicValue({ deviceId, serviceId, characteristicId: item.uuid, }) } if (item.properties.write && item.uuid.indexOf("0000FFF2") != -1) { this.setData({ canWrite: true, ble_status:1, }) this._deviceId = deviceId this._serviceId = serviceId this._characteristicId = item.uuid this.writeBLECharacteristicValue() } if (item.properties.notify || item.properties.indicate) { wx.notifyBLECharacteristicValueChange({ deviceId, serviceId, characteristicId: item.uuid, state: true, }) } } }, fail(res) { console.error('getBLEDeviceCharacteristics', res) } }) // 操作之前先监听,保证第一时间获取数据 wx.onBLECharacteristicValueChange((characteristic) => { const idx = inArray(this.data.chs, 'uuid', characteristic.characteristicId) const data = {} if (idx === -1) { data[`chs[${this.data.chs.length}]`] = { uuid: characteristic.characteristicId, value: ab2hex(characteristic.value) } } else { data[`chs[${idx}]`] = { uuid: characteristic.characteristicId, value: ab2hex(characteristic.value) } } // data[`chs[${this.data.chs.length}]`] = { // uuid: characteristic.characteristicId, // value: ab2hex(characteristic.value) // } this.setData(data) }) }, writeBLECharacteristicValue() { // 向蓝牙设备发送一个0x00的16进制数据 console.log('开始写入数据') let buffer = new ArrayBuffer(20) let dataView = new DataView(buffer) // dataView.setUint8(0, Math.random() * 255 | 0) for (let i = 0; i < 20; i++) { dataView[i] = i } wx.writeBLECharacteristicValue({ deviceId: this._deviceId, serviceId: this._serviceId, characteristicId: this._characteristicId, value: buffer, success: (res) => { console.log('writeBLECharacteristicValue success', JSON.stringify(res)) this.writeBLECharacteristicValue() }, fail: (res) => { console.log('writeBLECharacteristicValue fail', JSON.stringify(res)) //writeBLECharacteristicValue() } }) }, closeBluetoothAdapter() { wx.closeBluetoothAdapter() this._discoveryStarted = false this.setData({ ble_status: 0, }) },
2019-07-16我的昨天也碰到一样的问题了。还没解决。楼主加油
ios真机调试报错 define is not defined- 当前 Bug 的表现(可附上截图) - 预期表现 - 复现路径 - 提供一个最简复现 Demo 无法真机调试,好几天了。安卓机型没问题,ios全红...有没人解决啊... [图片]
2019-07-12我的也是,还要比你的慢,请问楼主解决了吗?
wx.writeBLECharacteristicValue效率问题在wx.writeBLECharacteristicValue AIP中. 该API处于低功耗蓝牙中. 想请问一下. 我在调用该API 速度有点慢 一共就6KB的数据. 传输了2分钟.. 我是传输数据到打印机 打印订单. 但是目前太慢了.
2019-07-11最后只能画布实现,事实上真机调试,使用saveFile保存后,路径为wxfile://,估摸着wxml中Image组建是不能识别吧,不过画布可以,就是稍微麻烦
本地保存图片成功后,如何在下个界面显示???有A,B,C三个界面,在B界面编辑画布并将图片路径保存在全局变量里,保存成功,请问如何在C界面显示啊? 保存的路径: [图片] 在C界面WXML中 <image class='CardImg' src="{{(jvCardNum>=2)?'ljvImgUrl2':'/img/carddemo.png'}}" 报错: [图片]
2019-03-27