使用WebBluetooth访问多个服务和特征

问题描述

我正在尝试读取体重秤的特性以及电池服务中当前的电池电量。

我有以下适用于体重秤服务和体重测量特性的产品,但是我正在努力寻找如何向其添加电池服务(我对诺言不太熟悉)

function connectGATT() {
  if (bluetoothDeviceDetected.gatt.connected && gattCharacteristic) {
    return Promise.resolve()
  }

  return bluetoothDeviceDetected.gatt.connect()
  .then(server => {
    console.log('Getting GATT Service...')
    return server.getPrimaryService(wsService)
    console.log(wsService)
  })
  .then(service => {
    console.log('Getting GATT Characteristic...')
    return service.getCharacteristic(wsCharacteristic)
    console.log(wsCharacteristic)
  })
  .then(characteristic => {
    gattCharacteristic = characteristic
    gattCharacteristic.addEventListener('characteristicvaluechanged',handleNotifications)
    document.querySelector('#start').disabled = false
    document.querySelector('#stop').disabled = true
  })
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)