GoogleChrome / samples

A repo containing samples tied to new functionality in each release of Google Chrome.
https://www.chromestatus.com/samples
Apache License 2.0
5.79k stars 2.38k forks source link

Difference between Scan and Watch sample #727

Open PierreClaret opened 3 years ago

PierreClaret commented 3 years ago

Hi I am trying to find the difference between the scan and watch advertisement ? Do they both do not need connexion ? I am also trying to find what the watchAdvertisement() function does ? Could anyone help me ?

beaufortfrancois commented 3 years ago

navigator.bluetooth.requestLEScan(options) starts scanning for BLE advertisements, asking the user for permission if they haven’t yet granted it. See https://webbluetoothcg.github.io/web-bluetooth/scanning#ref-for-dom-bluetooth-requestlescan%E2%91%A0 watchAdvertisements() requires you to have a BluetoothDevice first but not necessarily connected. user has to select it firs though. See https://webbluetoothcg.github.io/web-bluetooth/#ref-for-dom-bluetoothdevice-watchadvertisements%E2%91%A0

PierreClaret commented 3 years ago

Ok thank you ! I'm having trouble to get the Scan demo working I have tried on a Mac and a Windows. On the Mac I got an error message that state "Scan blocked by user" but I have enabled on chrome the experimental web platform. On windows the scan runs without stopping or getting any advertisement but I receive no error message. Would you happen to know why ?

beaufortfrancois commented 3 years ago

I can see the popup on macOS image

Make sure you didn't block "Bluetooth Scanning" by checking the lock browser icon

Do you have nearby Bluetooth devices when scanning around you?

PierreClaret commented 3 years ago

I have the pop up now. Sorry forgot about the lock... But I have no Bluetooth devices. However for the watch advertisement I can see multiple devices is it normal ?

beaufortfrancois commented 3 years ago

https://bugs.chromium.org/p/chromium/issues/detail?id=1155557#c3 may be the issue you're facing actually.

See if this hack works for you:

  1. Go to https://googlechrome.github.io/samples/web-bluetooth/scan.html?allAdvertisements=true
  2. Open DevTools console and execute navigator.bluetooth.requestDevice({acceptAllDevices: true})
  3. Dismiss browser picker
  4. Click "Scan for Bluetooth Advertisements" button
  5. Enjoy advertisements

image

PierreClaret commented 3 years ago

Hi Francois ! I was wondering what the event.Manufacturerdata.forEach does ? Cause I have a tag that sends manufacturer data but when I scan I only got the UUID of the device...

beaufortfrancois commented 3 years ago

https://webbluetoothcg.github.io/web-bluetooth/#ref-for-dom-bluetoothadvertisingevent-manufacturerdata is a map of manufacturer data broadcasted by the bluetooth device