- From: dodgePT via GitHub <sysbot+gh@w3.org>
- Date: Wed, 31 Jul 2019 11:29:34 +0000
- To: public-web-bluetooth-log@w3.org
dodgePT has just created a new issue for https://github.com/WebBluetoothCG/web-bluetooth:
== getPrimaryService(s) returns nothing ==
Hi all!
I'm experimenting with web bluetooth, trying to access services and characteristics on a BLE device, namely a smartwatch.
I'm on Win10 64bit, using electron framework but I also used the samples page to test this.
Everything goes according to plan up until I try to get services. It connects, I get the name, ID and gatt connected status, but then, when I try to get services, there's no response. It just stalls there, with no timeout, nothing.
First I thought this could be something related to electron, but then I tested all samples, and while they connect to the watch (just like my app), none of the samples are able to get any services too.
I got all UUIDs for services and characteristics of the watch, obtained through nRF Connect on Android.
Here's the simple class I made:
`class BTHuawei {
constructor() {
this.device = null;
this.onDisconnected = this.onDisconnected.bind(this);
this.characts = {};
}
request() {
let options = {
filters: [
{
namePrefix: "HUAWEI"
}
],
optionalServices: [
0x1800,
0x1801,
0x180a,
0x2902,
"0000fe86-0000-1000-8000-00805f9b34fb",
"00003802-0000-1000-8000-00805f9b34fb"
]
};
return navigator.bluetooth
.requestDevice(options)
.then(device => {
this.device = device;
this.device.addEventListener(
"gattserverdisconnected",
this.onDisconnected
);
})
.catch(error => {
console.log(error.message);
});
}
connect() {
console.log("Connecting...");
if (!this.device) {
return Promise.reject("Device is not connected.");
}
return this.device.gatt.connect();
}
//////////////////////////////////////////////////////////////////////////////
readCharacteristic(serviceUUID, characteristicUUID) {
return this.device.gatt
.getPrimaryService(serviceUUID)
.then(service => {
service
.getCharacteristic(characteristicUUID)
.then(characteristic => {
characteristic.startNotifications();
})
.then(characteristic => {
characteristic.addEventListener(
"characteristicvaluechanged",
handleCharacteristicValueChanged
);
characteristic.readValue();
});
});
}
discoverServicesAndCharacteristics() {
return this.device.gatt
.getPrimaryServices()
.then(services => {
let queue = Promise.resolve();
services.forEach(service => {
queue = queue.then(_ =>
service.getCharacteristics().then(characteristics => {
log("> Service: " + service.uuid);
characteristics.forEach(characteristic => {
console.log(
">> Characteristic: " +
characteristic.uuid +
" " +
getSupportedProperties(characteristic)
);
});
})
);
});
return queue;
})
.catch(error => {
console.log(error.message);
});
}
//////////////////////////////////////////////////////////////////////////////
disconnect() {
if (!this.device) {
return Promise.reject("Device is not connected.");
}
return this.device.gatt.disconnect();
}
onDisconnected() {
console.log("Device is disconnected.");
}
}`
And this is how I use it:
`bTHuawei
.request()
.then(_ => bTHuawei.connect())
.then(_ => {
console.log(bTHuawei.device.name);
console.log(bTHuawei.device.id);
console.log(bTHuawei.device.gatt.connected);
bTHuawei.readCharacteristic(0x1800, 0x2AA6);
})
.catch(error => {
console.log(error.message);
});`
Am I missing some step or something?
I guess not because none of the examples work after successfuly connecting.
Thank you for your time. Let me know if I can improve my query with more information.
Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/451 using your GitHub account
Received on Wednesday, 31 July 2019 11:29:36 UTC