Reputation: 43
I've recently implemented a BLE notifications system on an ESP32 board. My system has a specific service uuid and a specific characteristic uuid. I've set the notify property to the characteristic:
characteristic = service->createCharacteristic(
UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY
);
When I log the characteristic's properties into Chrome dev tools, the "notify" property appears to be "true":
Notify: true
But, when I use the startNotifications() on my characteristic I get this error message:
Uncaught (in promise) DOMException: GATT Error: Not supported.
This is the code I use :
try {
this.batteryLevelCharacteristic.startNotifications()
.then(characteristic => {
characteristic.addEventListener('characteristicvaluechanged',
handleCharacteristicValueChanged);
console.log('Notifications have been started.');
});
} catch(e) {
console.log(e);
}
I don't really understand the error... any idea ? :(
Thanks in advance !
NB : I use chrome Version 87.0.4280.88 on macOS Catalina 10.15.7
Upvotes: 4
Views: 359
Reputation: 966
Does your characteristic (defined on the ESP32) that you are trying to subscribe/notify to have the descriptor 0x2902 (CCC Descriptor) defined?
This is a requirement of the web-bluetooth implementation in Chrome per https://groups.google.com/a/chromium.org/g/web-bluetooth/c/TlHnA3hTksw
The other issue you could be running into is a problem with concurrency when writing to characteristics and introducing a delay could help. The comment from programmerRaj using an alert could be adding this delay, or the issue could also be due to interactivity (in-browser often you need to interact with the document such as a click event to grant permission).
I also ran into a similar problem; at least the same error. My BLE pererphial is defined/running in nodejs on a Raspberry pi 4. For me, the characteristic does have the descriptor and I've already tried a delay. After a lot of trial and error, I figured out the root cause of this.
The 0x2902 characteristic was duplicated, added by the framework (bleno) and also declared on the peripheral. I found this by looking at the device "on the air" using a BT app on my phone, and discovered the duplicate characteristic descriptor. Interestingly, the BT app could still subscribe to notifications but Chrome/web-bt was more fussy and threw this error when the descriptor was double defined.
Hope this helps someone else in the future!
Upvotes: 0