Page 1 of 1

BLE: what's the deal with handle and uuid?

Posted: 14:49, 16 Jan 2015
by mdings
Hi there,

I am just starting out developing an app which connects over BLE with an in-car odbii-device. I've gone through the documentation about the plugin and built a small prototype which connects successfully to the device. Now, I have the following question: why is the handle of a service or characteristic used in the interaction-methods instead of the uuid?

For example:

Code: Select all

evothings.ble.readCharacteristic(
   deviceHandle,
   characteristic.handle,
   function(data)
   {
      console.log('BLE characteristic data: ' + evothings.ble.fromUtf8(data));
   },
   function(errorCode)
   {
      console.log('BLE readCharacteristic error: ' + errorCode);
   });


The handle seems to change after each connection while the uuid stays the same? What's the idea behind this?
The uuid seems to me something that can be cached after first connection while for a characteristic's handle to be obtanined I need to go through the sequence of connecting -> reading services -> reading characteristics.
Or am I missing something here?

Re: BLE: what's the deal with handle and uuid?

Posted: 17:52, 16 Jan 2015
by Fredrik
Theoretically, there can be more than one characteristic with the same UUID. Therefore, we need a handle to distinguish between them.

Also, the native part of the plugin needs to enumerate the objects that correspond to each characteristic; those can't be cached.

There is a JavaScript library "easyble", distributed with the Evothings examples, that allow you to use UUIDs as you describe, at the cost of some computing time and a few kilobytes of code and data space. See ti-sensortag-demo for an example.