samples icon indicating copy to clipboard operation
samples copied to clipboard

Difference between Scan and Watch sample

Open PierreClaret opened this issue 4 years ago • 7 comments

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 ?

PierreClaret avatar Jun 11 '21 13:06 PierreClaret

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

beaufortfrancois avatar Jun 11 '21 13:06 beaufortfrancois

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 ?

PierreClaret avatar Jun 11 '21 13:06 PierreClaret

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?

beaufortfrancois avatar Jun 11 '21 13:06 beaufortfrancois

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 ?

PierreClaret avatar Jun 11 '21 14:06 PierreClaret

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

beaufortfrancois avatar Jun 14 '21 11:06 beaufortfrancois

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...

PierreClaret avatar Jun 17 '21 10:06 PierreClaret

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

beaufortfrancois avatar Jun 17 '21 10:06 beaufortfrancois