- 华为手机小程序做外围设备创建服务,连接ble调试软件成功,多次连接断开后,为什么报添加服务失败?
华为P50 -鸿蒙4.2.0系统,微信是最新版本,初始化蓝牙适配器,创建服务成功,发广播成功,多次连接断开后,调用BLEPeripheralServer.addService进入err报错,如图所示:[图片] 代码如下: let characteristics = [ { properties: { read: true, write: true, notify: true, }, permission: { readable: true, writeable: true },, uuid: CHARACTERISTIC_UUID, }, ]; characteristics.forEach((characteristic) => { if (that.data.phone === 'ios') { characteristic.value = new Uint8Array([0x00, 0x00]).buffer; } else if (that.data.phone === 'android') { characteristic.descriptors = [{ uuid: DESCRIPTORS_UUID, permission: { read: true, write: true }, }]; } }); // 添加服务 that.data.server?.addService({ service: { uuid: SERVICEID, characteristics: characteristics, }, success: () => { console.log('服务特征值创建成功'); //发送广播 that.data.server?.startAdvertising({ advertiseRequest: { deviceName:"test", serviceUuids: [SERVICEID] }, powerLevel: 'high', success: (res) => { console.log('开始广播啦!!!')}, fail: (err) => {console.error('广播失败啦', err)} }) }, fail: (err) => { console.log('服务特征值创建失败');} });
2天前 - 小米手机小程序做外围设备,发广播成功,但是无法发现创建的服务,为什么?
MIUI10.2.35稳定版小米9手机,微信最新版,调用BLEPeripheralServer.addService创建服务成功,并且发广播成功,用BLE调试工具,无法发现创建的服务SERVICEID,只有系统服务,为什么? let characteristics = [ { properties: { read: true, write: true, notify: true, }, permission: { readable: true, writeable: true },, uuid: CHARACTERISTIC_UUID, }, ]; characteristics.forEach((characteristic) => { if (that.data.phone === 'ios') { characteristic.value = new Uint8Array([0x00, 0x00]).buffer; } else if (that.data.phone === 'android') { characteristic.descriptors = [{ uuid: DESCRIPTORS_UUID, permission: { read: true, write: true }, }]; } }); // 添加服务 that.data.server?.addService({ service: { uuid: SERVICEID, characteristics: characteristics, }, success: () => { console.log('服务特征值创建成功'); //发送广播 that.data.server?.startAdvertising({ advertiseRequest: { deviceName:"test", serviceUuids: [SERVICEID] }, powerLevel: 'high', success: (res) => { console.log('开始广播啦!!!')}, fail: (err) => {console.error('广播失败啦', err)} }) }, fail: (err) => {} });
12-11