调用startAdvertising方法出现 no such server!错误
调用startAdvertising之前已经createBLEPeripheralServer成功。
createBLEPeripheralServer successed {errCode: 0, errMsg: "createBLEPeripheralServer:ok", server: t}
Server信息
t {serverId: "1617130829", services: Array(0), onCharacteristicReadRequest: ƒ, offCharacteristicReadRequest: ƒ, onCharacteristicWriteRequest: ƒ, …}
执行startAdvertising时报no such server错误
Advertising failed {errCode: 10020, errMsg: "startBLEPeripheralAdvertising:fail no such server! serverId: 1617130829"}
代码如下:
wx.openBluetoothAdapter({
//mode: 'peripheral',
success: (res) => {
console.info('Bluetooth adapter opened');
console.log('Creating BLEPeripheralServer');
wx.createBLEPeripheralServer({
success: (res) => {
console.info('createBLEPeripheralServer successed', res);
let server = res.server;
console.log(server);
let uuid = '000018F0-0000-1000-8000-00805F9BAAFB';
setInterval(() => {
console.info('advertising %s', uuid);
server.startAdvertising({
advertiseRequest: {
connectable: true,
serviceUuids: [
uuid
]
}
}).then(
(res) => {
console.log('Adverstising.. ', res);
},
(res) => {
console.warn('Advertising failed', res);
});
}, 5000);
},
fail: (res) => {
console.warn('createBLEPeripheralServer failed');
},
complete: (res) => {
console.debug('createBLEPeripheralServer completed');
}
});
},
fail: (res) => {
console.log('openBluetoothAdapter failed');
console.warn(res);
},
complete: (res) => {
console.debug('openBluetoothAdapter completed');
},
})
},