我正在尝试显示GATT服务器中服务的所有特征。这是代码...
navigator.bluetooth.requestDevice({
filters: [{
services: ['00001101-0000-1000-8000-00805f9b34fb']
}]})
.then(device => {
console.log('Connecting to GATT Server...');
return device.gatt.connect();
})
.then(server => {
console.log('Getting Services...');
return server.getPrimaryServices();
})
.then(services => {
console.log('Getting Characteristics...');
let queue = Promise.resolve();
services.forEach(service => {
queue = queue.then(_ => service.getCharacteristics().then(characteristics => {
console.log('> Service: ' + service.uuid);
characteristics.forEach(characteristic => {
console.log('>> Characteristic: ' + characteristic.uuid + ' ' +
getSupportedProperties(characteristic));
});
}));
});
return queue;
})
.catch(error => {
console.log('Argh! ' + error);
});
代码一直运行,直到它在第6行上将Connecting to GATT Server...
记录到控制台,并且不会继续打印下一个日志,这意味着device.gatt.connect()
在第7行上有问题。代码似乎正确,这可能是设备出现问题吗?有解决方案或建议吗?