语言

Menu
Sites
Language
Bluetooth LE discover all GATT services

I would like to discover all the GATT services a Bluetooth LE device my mobile app has connected to "contains". I cannot see the API which would allow me to do this. The uuids property of BluetoothLEDevice seems to contain only UUIDs which were included in the advertising packet. I need *all* services the device profile includes. This is a standard procedure when working with Bluetooth LE devices.

Thanks

function onConnected() {
    console.log("Connected to device");
    // NB at this point all we have are the UUIDs included in the ADV packet.
    var uuids = selected_device.uuids;
    var services = "";
    for (var i = 0; i < uuids.length; i++) {
        services += uuids[i] + "\n";
    }
    console.log ("Service found: " + services);    
}

 

 

编辑者为: Martin Woolley 19 1月, 2016
查看选择的答案

响应

6 回复
daniel kim

Hi,

I would suggest you to check this code from SDK help page.

 

function showGATTService(service, indent)
{
   if (indent === undefined)
   {
      indent = "";
   }

   console.log(indent + "Service " + service.uuid + ". Has " + service.characteristics.length
               + " characteristics and " + service.services.length + " sub-services.");

   for (var i = 0; i < service.services.length; i++)
   {
      showGATTService(service.services[i], indent + "   ");
   }
}

 var serviceUUIDs = remoteDevice.uuids;

 var i = 0, service = null;

for (i; i < serviceUUIDs.length; i++)
{

   service = remoteDevice.getService(serviceUUIDs[i]);

   showGATTService(service);
}

 

Hope this will help you.

Martin Woolley

Thanks Daniel but I don't think this helps. If I understand the code correctly it lets you "show" a primary service and each of the secondary services it contains (by recursion). You need to know a service UUID before you can call it. I'm looking for a function which will discover all services from a connected device. Android (and every other smartphone platform I know) supports this as service discovery is a basic Bluetooth LE operation. See Android's BluetoothGatt class and its discoverServices() method for example.

Aditya Aswani

var serviceUUIDs = remoteDevice.uuids

I suppose once connected to the remote device "remoteDevice.uuids" will give an exhaustive list of services present with the remote device , not just the services in the ADV.

Martin Woolley

Hi Aditya

according to my testing, the content of the remoteDevice.uuids property does not change when you connect. There's no evidence of an automatic service/characteristic/discovery process going on. 

I have a protocol analyser so maybe I'll verify this with some tracing. Right now it just looks like Tizen doesn't support this essential use case.

Mark as answer
Martin Woolley

Samsung have confirmed to me that this functionality is not available today using the web SDK but that it is available to native apps:

https://developer.tizen.org/dev-guide/latest/org.tizen.native.mobile.apireference/group__CAPI__NETWORK__BLUETOOTH__GATT__MODULE.html#ga48354aa3ff1cacd5df245287ccb7b99c 

 

AVSukhov

thanks for sharing info.