Author Topic: Discovering BLE devices with just specific services?  (Read 510 times)

Offline mdlieder

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Discovering BLE devices with just specific services?
« on: January 18, 2019, 01:20:31 AM »
Hello! Is there any way to do a discover for BLE devices matching a certain service short UUID? It's part of the BLE advertising packet I believe and iOS's discover service supports that (https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518986-scanforperipherals) so it should technically be possible. Closest I've found in the framework is radio.EnumRemoteServices, but since it doesn't appear to accept a short UUI and it's not quick it unfortunately doesn't work for my use case (enumerating BLE heart rate monitors, short UUID 0x180D).

Thanks!

Offline mdlieder

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Discovering BLE devices with just specific services?
« Reply #1 on: January 18, 2019, 01:57:59 AM »
Looks like it's possible using BluetoothLEAdvertisingWatcher in the Windows API: https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementwatcher.-ctor#Windows_Devices_Bluetooth_Advertisement_BluetoothLEAdvertisementWatcher__ctor_Windows_Devices_Bluetooth_Advertisement_BluetoothLEAdvertisementFilter_

I haven't tried it yet, but looking through your beacon code I believe I could use wclBluetoothLeBeaconWatcher to scan for "AdvertisementUuidFrame"s that match the service UUID I'm looking for, and then use the address associated with the frame to connect to the device using the standard API.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3386
  • Karma: 1000
    • Wireless Communication Libraries
Re: Discovering BLE devices with just specific services?
« Reply #2 on: January 18, 2019, 02:03:24 AM »
Hello! Is there any way to do a discover for BLE devices matching a certain service short UUID? It's part of the BLE advertising packet I believe and iOS's discover service supports that (https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518986-scanforperipherals) so it should technically be possible. Closest I've found in the framework is radio.EnumRemoteServices, but since it doesn't appear to accept a short UUI and it's not quick it unfortunately doesn't work for my use case (enumerating BLE heart rate monitors, short UUID 0x180D).

Thanks!

No, Bluetooth Framework does not support such feature.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3386
  • Karma: 1000
    • Wireless Communication Libraries
Re: Discovering BLE devices with just specific services?
« Reply #3 on: January 18, 2019, 02:04:28 AM »
Looks like it's possible using BluetoothLEAdvertisingWatcher in the Windows API: https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementwatcher.-ctor#Windows_Devices_Bluetooth_Advertisement_BluetoothLEAdvertisementWatcher__ctor_Windows_Devices_Bluetooth_Advertisement_BluetoothLEAdvertisementFilter_

I haven't tried it yet, but looking through your beacon code I believe I could use wclBluetoothLeBeaconWatcher to scan for "AdvertisementUuidFrame"s that match the service UUID I'm looking for, and then use the address associated with the frame to connect to the device using the standard API.

You are mixing up 2 different things. GATT service you are reffered to in your first question about HeatRate monitor BLE device and BLE Advertiser (Beacon). The UUID advertised may be or may not be the same as GATT services UUIDs.

Offline mdlieder

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Discovering BLE devices with just specific services?
« Reply #4 on: January 30, 2019, 09:16:35 PM »
FYI this technique is working great for me! Tested it successfully with both a Cardiosport strap and a Scosche Rhythm+.

Example code:

Code: [Select]
private void wclBluetoothLeBeaconWatcher_OnAdvertisementUuidFrame(object sender, long address, long timestamp, sbyte rssi, Guid uuid)
{
// look for a device advertising that it has a HeartRateService, adding it if so
if (uuid == Guid.Parse("0000180d-0000-1000-8000-00805f9b34fb"))
{
// add to list of devices
}
}

// later, after enumeration is over and the user has chosen the HRM they want to connect to
Client = new wclGattClient
{
Address = address
};
Client.Connect(Radio);
// read services, locate HeartRateService, read its characteristics, find the HeartRateMeasurement characteristic, and subscribe to it

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3386
  • Karma: 1000
    • Wireless Communication Libraries
Re: Discovering BLE devices with just specific services?
« Reply #5 on: January 30, 2019, 09:37:08 PM »
Hello,

That can be used but not with all devices. In fact not all BLE devices advertise services they support in connectable GATT mode.

If your device does so the way you described is absolutely correct.

 

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14