【发布时间】:2017-05-04 15:15:16
【问题描述】:
TL;DR;
我的问题是:
目前https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth 的网络蓝牙 API 是否不完全支持某些自定义设备,例如 Arduino 板?因为当我尝试在我的 Bluno Beetle 板上使用
BluetoothRemoteGATTCharacteristic.startNotifications()时遇到了DOMException: GATT Error: Not supported.异常。-
如果
startNotifications()完全实现。那么,我的 Bluno 板上是否需要配置任何额外设置才能使通知正常工作?从大多数在线示例中,没有提及在使用此方法之前设备上的额外设置。我在运行时检查了目标特征的notify属性是true。如https://webbluetoothcg.github.io/web-bluetooth/ 所述,这不应该是出现此异常的原因:If neither of the Notify or Indicate bits are set in characteristic’s properties, reject promise with a NotSupportedError and abort these steps.
我的情况:
我正在尝试在 chrome 上构建一个小的网络演示,它可以输出从我的 Bluno Beetle v1.0 板传输的文本。
我的板子里面的程序很简单:
void setup() {
Serial.begin(115200); //initial the Serial
}
void loop() {
Serial.write("hello world");
Serial.println();
delay(500);
}
我正在使用 developer.mozilla.org 的网络蓝牙 API
// UUID using by Bluno Beetle
var RXTX_SERVICE = 0xdfb0;
var RXTX_CHARACTERISTIC = 0xdfb2;
function handleCharacteristicValueChanged(event) {
var value = event.target.value;
}
navigator.bluetooth.requestDevice({ acceptAllDevices: true, optionalServices: [RXTX_SERVICE] })
.then(device => { console.log(device); return device.gatt.connect(); })
.then(server => { return server.getPrimaryService(RXTX_SERVICE); })
.then(service => { return service.getCharacteristic(RXTX_CHARACTERISTIC); })
.then(ch => { console.log(ch);
ch.addEventListener('characteristicvaluechanged', handleCharacteristicValueChanged);
console.log('Notifications have been started.');
return ch;
})
.then(ch => { return ch.startNotifications() })
.catch(error => { console.log(error); });
一切都很顺利,但是,我在执行该行时遇到了这个异常:ch.startNotifications()
DOMException: GATT Error: Not supported.
我尝试使用 iOS/Android APP 来执行相同的任务,并且两个 APP 都在处理该特性更改的通知。所以我假设我的 Bluno 板在某些配置下工作正常。但我找不到网络蓝牙 API 对我克服这个问题有用。
任何帮助将不胜感激!谢谢。
【问题讨论】:
-
你最终能成功吗?缺少描述符似乎存在更严重的问题,这使得 Bluno 与 Web 蓝牙(以及大多数 BLE 设备,因为它不符合协议)不兼容。见dfrobot.com/forum/viewtopic.php?t=2035
标签: javascript google-chrome bluetooth arduino web-bluetooth