【1】实际上控制的是android.bluetooth.le.AdvertiseSettings.Builder#setConnectable 【2】需要输入"0x013A"。另外该版本manufactureData有bug,可以用测试版验证下https://szsupport.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/android_exp__index 【3】 不会缓存,设置到adapter的deviceName可能不会立刻修改到,但是广播中的deviceName是会立即修改的,另外为了节约广播的数据包,devceiName为blank的话是不会在广播中include deviceName的 【4】 同2
BLEPeripheralServer.startAdvertising广播数据包内容不可控本代码片段预期实现内容: 1.点击按钮,BLE外设服务,即BLEPeripheralServer,并进行BLE广播。 2.BLE外设的广播数据内容,根据代码设置为: 1)不可链接; 2)厂商ID设为:0x013A; 3)广播名为:”DigCore“; 4)广播功率:powerLevel: "high" 然而经过多次调试发现,广播数据不受控制: 1)BLE外设无法设置为不可连接; 2)厂商ID无法设置为预期值,而一直是:0x0000进行广播 3)广播名无法删除,只能修改;即如果广播名不设置,小程序服务器是否缓存了上一次的广播名? 4)广播功率出现 0 dBm,而且一个广播包中出现两组广播功率的AD_Structure。
2020-03-30可以参考这份示例代码 const uuid1 = '000018F0-0000-1000-8000-00805F9BAAFB' const uuid2 = '00002AF0-0000-1000-8000-00805F9BBBFB' const uuid3 = '00002AF1-0000-1000-8000-00805F9BCCFB' // ArrayBuffer转16进制字符串示例 function ab2hex(buffer) { let hexArr = Array.prototype.map.call( new Uint8Array(buffer), function (bit) { return ('00' + bit.toString(16)).slice(-2) } ) return hexArr.join(''); } function inArray(arr, key, val) { for (let i = 0; i < arr.length; i++) { if (arr[i][key] === val) { return i; } } return -1; } // slave/slave.js Page({ /** * 页面的初始数据 */ data: { connects: [], servers: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.onBLEPeripheralConnectionStateChanged(res => { console.log('ConnectionStateChanged', res) const connects = this.data.connects const idx = inArray(connects, 'deviceId', res.deviceId) if (idx >= 0) { connects[idx] = res } else { connects.push(res) } this.setData({ connects }) }) }, openBluetoothAdapter() { wx.openBluetoothAdapter({ success: (res) => { console.log('openBluetoothAdapter success', res) this.createBLEPeripheralServer() wx.onBluetoothAdapterStateChange(function (res) { console.log('onBluetoothAdapterStateChange', res.available) }) }, fail: (res) => { if (res.errCode === 10001) { console.log("ble unavailable!") } } }) }, createBLEPeripheralServer() { wx.createBLEPeripheralServer().then(res => { console.log('createBLEPeripheralServer', res) this.data.servers.push(res.server) this.server = res.server this.setData({ serverId: this.server.serverId }) this.server.onCharacteristicReadRequest(res => { const { serviceId, characteristicId, callbackId } = res const buffer = new ArrayBuffer(1) const dataView = new DataView(buffer) const newValue = Math.ceil(Math.random() * 10) dataView.setUint8(0, newValue) console.log('onCharacteristicReadRequest', res, newValue) this.server.writeCharacteristicValue({ serviceId, characteristicId, value: buffer, needNotify: true, callbackId }) }) this.server.onCharacteristicWriteRequest(res => { console.log('onCharacteristicWriteRequest', res) const { serviceId, characteristicId, value, callbackId } = res this.server.writeCharacteristicValue({ serviceId, characteristicId, value, needNotify: true, callbackId }) }) }) }, closeServer() { this.server.close() }, onConfirm(e) { const n = e.detail.value * 1 const buffer = new ArrayBuffer(1) const dataView = new DataView(buffer) dataView.setUint8(0, n) this.server.writeCharacteristicValue({ serviceId: uuid1, characteristicId: uuid2, value: buffer, needNotify: true }) }, showInput() { this.setData({ input: !this.data.input }) }, addService() { const buffer = new ArrayBuffer(2) const dataView = new DataView(buffer) dataView.setUint8(0, 9) dataView.setUint8(1, 11) const descriptorBuffer = new ArrayBuffer(2) const dataView2 = new DataView(descriptorBuffer) dataView2.setInt8(0, 1) dataView2.setInt8(1, 0) const service = { uuid: uuid1, characteristics: [{ uuid: uuid2, properties: { write: false, read: true, notify: true, indicate: false }, permission: { readable: true, writeable: false, readEncryptionRequired: false, writeEncryptionRequired: false }, value: buffer, descriptors: [{ uuid: uuid2, permission: { write: false, read: true }, value: descriptorBuffer }] }, { uuid: uuid3, properties: { write: true, read: false, notify: false, indicate: false }, permission: { readable: false, writeable: true, readEncryptionRequired: false, writeEncryptionRequired: false }, value: buffer, descriptors: [{ uuid: uuid3, permission: { write: true, read: false }, value: descriptorBuffer }] }] } this.server.addService({ service }).then(res => { console.log('add Service', res) }) }, removeService() { this.server.removeService({ serviceId: uuid1 }).then(res => { console.log('removeService', res) }) }, startAdvertising() { const buffer = new ArrayBuffer(1) const dataView = new DataView(buffer) var hex = "7E9" var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) { return parseInt(h, 16) })) this.server.startAdvertising({ advertiseRequest: { connectable: true, deviceName: '', serviceUuids: [uuid1], manufacturerData: [{ manufacturerId: '0x004c', manufacturerSpecificData: typedArray.buffer }] }, powerLevel: 'higt' }).then(res => { console.log('startAdvertising', res) }, res => { console.log("fail: ", res) }) }, stopAdvertising() { this.server.stopAdvertising() }, closeBluetoothAdapter() { wx.closeBluetoothAdapter() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { this.data.servers.forEach(server => { // server.close() }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })
调用BLEPeripheralServer.addService一直报错https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-peripheral/BLEPeripheralServer.addService.html [图片] 下面是addService的代码: [图片]
2020-03-23可以参考这份示例代码 const uuid1 = '000018F0-0000-1000-8000-00805F9BAAFB' const uuid2 = '00002AF0-0000-1000-8000-00805F9BBBFB' const uuid3 = '00002AF1-0000-1000-8000-00805F9BCCFB' // ArrayBuffer转16进制字符串示例 function ab2hex(buffer) { let hexArr = Array.prototype.map.call( new Uint8Array(buffer), function (bit) { return ('00' + bit.toString(16)).slice(-2) } ) return hexArr.join(''); } function inArray(arr, key, val) { for (let i = 0; i < arr.length; i++) { if (arr[i][key] === val) { return i; } } return -1; } // slave/slave.js Page({ /** * 页面的初始数据 */ data: { connects: [], servers: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.onBLEPeripheralConnectionStateChanged(res => { console.log('ConnectionStateChanged', res) const connects = this.data.connects const idx = inArray(connects, 'deviceId', res.deviceId) if (idx >= 0) { connects[idx] = res } else { connects.push(res) } this.setData({ connects }) }) }, openBluetoothAdapter() { wx.openBluetoothAdapter({ success: (res) => { console.log('openBluetoothAdapter success', res) this.createBLEPeripheralServer() wx.onBluetoothAdapterStateChange(function (res) { console.log('onBluetoothAdapterStateChange', res.available) }) }, fail: (res) => { if (res.errCode === 10001) { console.log("ble unavailable!") } } }) }, createBLEPeripheralServer() { wx.createBLEPeripheralServer().then(res => { console.log('createBLEPeripheralServer', res) this.data.servers.push(res.server) this.server = res.server this.setData({ serverId: this.server.serverId }) this.server.onCharacteristicReadRequest(res => { const { serviceId, characteristicId, callbackId } = res const buffer = new ArrayBuffer(1) const dataView = new DataView(buffer) const newValue = Math.ceil(Math.random() * 10) dataView.setUint8(0, newValue) console.log('onCharacteristicReadRequest', res, newValue) this.server.writeCharacteristicValue({ serviceId, characteristicId, value: buffer, needNotify: true, callbackId }) }) this.server.onCharacteristicWriteRequest(res => { console.log('onCharacteristicWriteRequest', res) const { serviceId, characteristicId, value, callbackId } = res this.server.writeCharacteristicValue({ serviceId, characteristicId, value, needNotify: true, callbackId }) }) }) }, closeServer() { this.server.close() }, onConfirm(e) { const n = e.detail.value * 1 const buffer = new ArrayBuffer(1) const dataView = new DataView(buffer) dataView.setUint8(0, n) this.server.writeCharacteristicValue({ serviceId: uuid1, characteristicId: uuid2, value: buffer, needNotify: true }) }, showInput() { this.setData({ input: !this.data.input }) }, addService() { const buffer = new ArrayBuffer(2) const dataView = new DataView(buffer) dataView.setUint8(0, 9) dataView.setUint8(1, 11) const descriptorBuffer = new ArrayBuffer(2) const dataView2 = new DataView(descriptorBuffer) dataView2.setInt8(0, 1) dataView2.setInt8(1, 0) const service = { uuid: uuid1, characteristics: [{ uuid: uuid2, properties: { write: false, read: true, notify: true, indicate: false }, permission: { readable: true, writeable: false, readEncryptionRequired: false, writeEncryptionRequired: false }, value: buffer, descriptors: [{ uuid: uuid2, permission: { write: false, read: true }, value: descriptorBuffer }] }, { uuid: uuid3, properties: { write: true, read: false, notify: false, indicate: false }, permission: { readable: false, writeable: true, readEncryptionRequired: false, writeEncryptionRequired: false }, value: buffer, descriptors: [{ uuid: uuid3, permission: { write: true, read: false }, value: descriptorBuffer }] }] } this.server.addService({ service }).then(res => { console.log('add Service', res) }) }, removeService() { this.server.removeService({ serviceId: uuid1 }).then(res => { console.log('removeService', res) }) }, startAdvertising() { const buffer = new ArrayBuffer(1) const dataView = new DataView(buffer) var hex = "7E9" var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) { return parseInt(h, 16) })) this.server.startAdvertising({ advertiseRequest: { connectable: true, deviceName: '', serviceUuids: [uuid1], manufacturerData: [{ manufacturerId: '0x004c', manufacturerSpecificData: typedArray.buffer }] }, powerLevel: 'higt' }).then(res => { console.log('startAdvertising', res) }, res => { console.log("fail: ", res) }) }, stopAdvertising() { this.server.stopAdvertising() }, closeBluetoothAdapter() { wx.closeBluetoothAdapter() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { this.data.servers.forEach(server => { // server.close() }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })
调用BLEPeripheralServer.addService报错建立本地作为外围设备的服务端之后,调用BLEPeripheralServer.addService报错{errMsg: "addBLEPeripheralService:fail addBLEPeripheralService valueBase64String is empty."} [图片] https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-peripheral/BLEPeripheralServer.addService.html
2020-03-23你好,加载不出来的原因是因为使用了TLS 1.0或者TLS 1.1,请使用1.2或者更高的版本。
华为公司的手机,wx.previewImage 黑屏- 当前 Bug 的表现(可附上截图) wx.previewImage({ current: "https://image.dqccc.com/c_photo/2019/03/12/1145061645219.jpg", //数据源 urls: [ "https://image.dqccc.com/c_photo/2019/03/12/1145061645219.jpg", "https://image.dqccc.com/c_photo/2019/03/12/1143521794116.jpg", "https://image.dqccc.com/c_photo/2019/03/09/1219124252866.jpg" ] }); 好多人都遇见这个问题了,你们难道就不解决吗??? 难道让我们给用户换个手机.... 这样的代码肯定没问题, 苹果、小米手机都能正常显示!!!!!!! [图片]
2019-07-10你好,问题的原因在于,你提供的jpg图片的url对应的服务器会对HTTP的User-Agent做校验,校验不通过会返回网页而不是图片,所以显示不出来。
wx.previewImage安卓手机显示黑屏调用wx.previewImage预览图片时,苹果手机打开正常,安卓手机显示黑屏,更换小米、华为都显示黑屏,请问是什么问题??
2019-07-09