Search code examples
javaeclipseosgibluetooth-lowenergykura

Using kura framework, how can I specify the address type to "random static" when connecting to a BLE device


I'm trying to create an OSGi bundle that'd be installed on a eurotech gateway (reliagate 10 05). This bundle would essentially connect the gateway to a BLE device.

To do so, I use a framework provided by eurotech called Everyware™ Software Framework (ESF) that adds up an extra layer on top of the kura v1.2.0 framework.

The catch is, the BLE device only accepts random static address type.

I managed to connect the gateway manually to the BLE device using the following commands in console:

hcitool -i hci0 lecc --random <BD_ADDR>

then

gatttool -i hci0 -b <BD_ADDR> --interactive

This works fine. The hard part is when I try to do the same thing in code using the ESF/kura framework.

Here's a snippet from a sample I use that I found on this page

public boolean connect(String adapterName) {
    this.bluetoothGatt = this.device.getBluetoothGatt();
    boolean connected = false;
    try {
          connected = this.bluetoothGatt.connect(adapterName);
    } catch (KuraException e) {
          logger.error(e.toString());
    }
    if (connected) {
        this.bluetoothGatt.setBluetoothLeNotificationListener(this);
        this.isConnected = true;
        return true;
    } else {
       // If connect command is not executed, close gatttool
        this.bluetoothGatt.disconnect();
        this.isConnected = false;
        return false;
    }
}

Here is a list of some objects that the sample uses to scan and establish a connection:

org.eclipse.kura.bluetooth.BluetoothAdapter;
org.eclipse.kura.bluetooth.BluetoothDevice;
org.eclipse.kura.bluetooth.BluetoothGattSecurityLevel;
org.eclipse.kura.bluetooth.BluetoothGattService;
org.eclipse.kura.bluetooth.BluetoothLeScanListener;
org.eclipse.kura.bluetooth.BluetoothService;
org.eclipse.kura.bluetooth.BluetoothDevice;
org.eclipse.kura.bluetooth.BluetoothGatt;
org.eclipse.kura.bluetooth.BluetoothGattCharacteristic;
org.eclipse.kura.bluetooth.BluetoothLeNotificationListener;

So I searched through the api doc but didn't find anything.

Though, one interesting SO post mentions a command code to send to the device.

I found a method in kura framework that might help. Here's the signature:

void ExecuteCmd(java.lang.String ogf, java.lang.String ocf, java.lang.String parameter)

but I couldn't figure out the OpCode Group Field (ogf) associated to the OpCode Command Field(ocf) in any documentation (I skimmed the ~2300 pages of the Bluetooth 4.0 core spec). If anyone knows where to search... :)

In the end, the question is: is there a way to set the address type to random (as with the hcitool command) with the kura framework ? Or am I totally misleaded ? :/

Anyway, I'm really new to the kura and ble ecosystems so, sorry if it looks like an obvious thing to do but I feel like I'm running out of inspiration and could totally use a hand!

PS: Congrats if you made it to the end!


Solution

  • Okay so for those who find themselves in my position in the future, I just received an answer from the Eurotech support team.

    Dear Mr. Carneiro,

    [...]

    Regarding the random BD_ADDR, this is a configuration of the BLE device. So, your BLE device is advertising an address of type random, not public, and you should specify the address type on the connection string, as you already did. Unfortunately, current Kura Bluetooth API doesn't provide a way to specify the type of address into the connection string. We are developing a new set of APIs for BLE that will be available on preview on the next Kura/ESF release, but the Reliagate 10-05 will not support these yet.