-
• #2
Hi! Actually someone else had exactly this problem recently!
The issue is that
setServices
sets the services that are available once you're connected to the device. There's another type of services - advertised services - that are broadcast to everyone even when not connected, and it's those that Web Bluetooth is looking for.It's actually in the second half of the setServices docs: https://www.espruino.com/Reference#l_NRF_setServices
Something like this should fix it:
NRF.setServices({ 0x180F : { // Battery Service 0x2A19: { // Battery Level readable: true, notify: true, value : [Puck.getBatteryPercentage()] }}},{ advertise: [ '180F' ] });
Out of interest, any thoughts about where I could put some info on this so others are less likely to fall into the same trap :)
-
• #3
Hi Gordon!
Thanks, this works. :-) Regarding where to put some info on this: It would be great to have a tutorial, using the Puck.js together with the web bluetooth API (not only with your wrapper class).
Now, I have some other questions regarding this:
- Do you know if it's possible to connect multiple devices at once via Web Bluetooth?
- Do you know if I can connect to devices automatically via Web Bluetooth? (Let's say: Remember a device and if it's reachable, Web Bluetooth should automatically connect to it)
- Using the characteristicvaluechanged event, I should be able to get the real time data, every time the battery percentage changes, right?
- Do you know if it's possible to connect multiple devices at once via Web Bluetooth?
-
• #4
Thanks - yes, I'll have a go at that :)
Do you know if it's possible to connect multiple devices at once via Web Bluetooth?
It is, yes! It depends on your platform, but it's around 5 or 6 maximumDo you know if I can connect to devices automatically via Web Bluetooth? (Let's say: Remember a device and if it's reachable, Web Bluetooth should automatically connect to it)
I don't believe so - yet. That's one of the things they're looking into though.
Using the characteristicvaluechanged event, I should be able to get the real time data, every time the battery percentage changes, right?
Yes, absolutely - as long as
notify:true
in that Puck.js service :)
Hi! I'm trying to read data from the puck.js over web bluetooth. As a PoC I just wanted to read the battery percentage, but it doesn't work: The Puck.js does not appear on the list for the bluetooth devices in the web browser. My assumption is, that the web bluetooth library does not know, that my puck is advertising battery data.. Any idea how to fix this?
The code on my Puck.js:
For testing purposes I used the Web Bluetooth Sample page: https://googlechrome.github.io/samples/web-bluetooth/battery-level.html