1

I am trying to achieve a UWB communication between the two devices with the help of Bluetooth(ble) in android. There is no specific documentation available regarding the same. Google provides this as a sample.

https://github.com/android/connectivity-samples/tree/main/UwbRanging

The above code creates a connection with the help of a nearby api and uses the endpoint to create a session.

If we see the code. The steps are as follows. Start discovery with the nearby api.

fun startDiscovery() = callbackFlow {
    dispatchEvent = { trySend(it) }
    coroutineScope.launch {
      connectionsClient
        .startDiscovery(
          CONNECTION_SERVICE_ID,
          endpointDiscoveryCallback,
          DiscoveryOptions.Builder().setStrategy(Strategy.P2P_CLUSTER).build()
        )
        .await()
    }

The above is done by the controller.

Similarly for the controlee the following code execute.

fun startAdvertising() = callbackFlow {
    dispatchEvent = { trySend(it) }
    coroutineScope.launch {
      connectionsClient
        .startAdvertising(
          CONNECTION_NAME,
          CONNECTION_SERVICE_ID,
          connectionLifecycleCallback,
          AdvertisingOptions.Builder().setStrategy(Strategy.P2P_CLUSTER).build()
        )
        .await()
    }
    awaitClose {
      disconnectAll()
      connectionsClient.stopAdvertising()
    }
  }

In the discovery callback by the controller one endpoint is received which is used to request the connection

private val endpointDiscoveryCallback =
    object : EndpointDiscoveryCallback() {
      override fun onEndpointFound(endpointId: String, info: DiscoveredEndpointInfo) {
        Log.d("endpointid",endpointId + info.endpointName + " " + info.endpointInfo)
        coroutineScope.launch {
          connectionsClient
            .requestConnection(CONNECTION_NAME, endpointId, connectionLifecycleCallback)
        }
      }

Similarly for ble we have the methods

bluetoothLeScanner?.startScan(scanCallback)

and

advertiser.startAdvertisingSet(parameters, data, null, null, null, callback);

Which data from the above ble scan and advertise can be accessed and how can we create the ranging parameters for uwb from the same.

So that once the connection is established with the gatt client. We can do create the ranging parameters like

 val uwbConfigType: Int,
    val sessionId: Int,
    val sessionKeyInfo: ByteArray?,
    val complexChannel: UwbComplexChannel?,
    val peerDevices: List<UwbDevice>,
    val updateRateType: Int

So here are my two questions 1.How to redrive the above parameters using the BLE ? 2. Is it possible to achieve the same without advertising as client in the case of BLE ?

Thank you.

Pritish
  • 1,284
  • 1
  • 19
  • 42

1 Answers1

0

The Jetpack UWB library doesn't handle the out-of-band (OOB) parameter exchange. If you want to use BLE as the OOB medium, one way to do it is:

  1. At the BLE advertiser side, create a UwbControleeSessionScope and call UwbClientSessionScope#rangingCapabilities to get the device's ranging capabilities and call UwbClientSessionScope#localAddress to get the device's per-session-based UWB address.
  2. You can either put the information (at the minimum, the UWB address) in the BLE advertisement or send the information when GATT is connected.
  3. Start advertising with your UUID.
  4. At the BLE scanner side, start scan and open the GATT connection when the UUID is discovered.
  5. If the controlee address/rangingCapabilities are not in the advertisement, the advertiser needs to send it to the scanner through GATT read or indication/notification.
  6. The scanner checks the received data and creates a UwbControllerSessionScope and call UwbClientSessionScope#localAddress and UwbClientSessionScope#uwbComplexChannel to obtain the scanner's UWB address and the complex channel used for ranging.
  7. The scanner Create a RangingParameters object, you can randomly generate sessionId and 8-byte-long sessionKeyInfo.
  8. The scanner sends the sessionId, sessionKeyInfp, controller address etc. to the advertiser.
  9. The advertiser can create its own RangingParameters object at this stage.
  10. Both sides start ranging.
Torsten Scholz
  • 856
  • 1
  • 9
  • 22
  • Thanks for replying :) . So I would like to understand what is the use of gatt connection or for that matter even ble if i have two known devices.. Lets say for testing purpose , I have two known devices and I am able to get there respective mac address , can I directly connect it using the hardcoded values ? Or is it that first gatt connection has to be established between the two devices and only then uwb will work ? Similarly is it possible for you to give a code example for the steps above ? Thanks. – Pritish Jun 29 '23 at 11:33
  • The address and complex channel rotates every session. So you need to exchange them for every new session. – Xiangjun Zhao Jun 30 '23 at 18:55