Web Bluetooth - Can I retrieve a list of all services within a device?
Asked Answered
A

1

10

I've been basing my project on the discover services and characteristics sample project: https://googlechrome.github.io/samples/web-bluetooth/discover-services-and-characteristics.html

I'm trying to log a list of all available services within a device into the Chrome console. Is there a possibility to do this? Because if I don't enter a service ID, I encounter a securityError: "Argh! SecurityError: Origin is not allowed to access any service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options."

I know NRF Connect can detect all services.

So can I retrieve a list of all services from a device, without predefining the services?

Any ideas would be appreciated.

Alderete answered 17/4, 2020 at 15:17 Comment(0)
M
13

Short answer: No, you have to list the services you want access to.

Web Bluetooth is designed with user privacy in mind, and requires services an application wants to access to be listed in the requestDevice call so that browsers can offer an appropriate amount of communications to users. There is a way to request to connect to any device acceptAllDevices: true, but there is not a way to request access to all services on the device.

When you're developing and need to understand what Chrome can see on a device you can use chrome://bluetooth-internals/#devices. Start a scan to find devices, and then select Inspect. (Only some devices will accept a connection.)

NRF Connect is an excellent and more powerful tool as well.

The current design for Web Bluetooth doesn't support building that level of diagnostic application. More about the security & privacy model for Web Bluetooth is in the Web Bluetooth specification.

One good developer facing article on these topics: https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web

Melodimelodia answered 18/4, 2020 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.