调用startAdvertising方法出现 no such server!错误
发布于 6 年前 作者 tao14 9460 次浏览 来自 官方Issues

https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-peripheral/BLEPeripheralServer.startAdvertising.html

调用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');
      },
    })
  },
回到顶部