Reputation: 11
I am building an app that will set up a ranging session between 2 android phones that support UWB, without using any OOB mechanism like BLE, WiFi etc., but hard coding the parameters.
I initiate the session on both the controller and the controlee and when I try to add the controlee to the ranging session the app crashes.
val uwbManager = UwbManager.createInstance(applicationContext)
var job: Job?
val uwbDevice = UwbDevice.createForAddress("42:43")
val uwbChannel = UwbComplexChannel(5,9)
fun doSomethingWithThePosition(context: RangingPosition) {
println("Ranging position obtained: ")
}
fun handlePeerDisconnect(rangingResult: RangingResult.RangingResultPeerDisconnected) {
println("Peer has disconnected")
}
suspend fun startRanging() {
val controllerSession = uwbManager.controllerSessionScope()
//val coroutineScope = CoroutineScope(Dispatchers.IO + Job())
val partnerParameters = RangingParameters(
uwbConfigType = RangingParameters.CONFIG_UNICAST_DS_TWR,
sessionId = 0,
subSessionId = 0,
sessionKeyInfo = null,
subSessionKeyInfo = null,
complexChannel = uwbChannel,
peerDevices = listOf(uwbDevice),
updateRateType = RangingParameters.RANGING_UPDATE_RATE_AUTOMATIC
)
val sessionFlow = controllerSession.prepareSession(partnerParameters)
CoroutineScope(Dispatchers.Main.immediate).launch {
sessionFlow.collect {
when(it) {
is RangingResult.RangingResultPosition -> {
doSomethingWithThePosition(it.position)
}
is RangingResult.RangingResultPeerDisconnected -> handlePeerDisconnect(it)
}
}
}
try {
// ADD A CONTROLEE, PASS ITS UWB_ADDRESS
controllerSession.addControlee(uwbDevice.address)
} catch (e: Exception) {
Log.e(TAG, "An exception occured when adding a controlee", e)
}
}
var rangingResult = RangingResult.RangingResultPosition(device = uwbDevice, position = RangingPosition(
distance = null, elevation = null, azimuth = null, elapsedRealtimeNanos = 0
))
Tried adding a controlee with fixed parameters, however I get an error:
An exception occured when adding a controlee
java.lang.IllegalStateException: Please check that the ranging is active and theranging profile supports multi-device ranging.
at androidx.core.uwb.impl.UwbControllerSessionScopeImpl.addControlee(UwbControllerSessionScopeImpl.kt:47)
at androidx.core.uwb.impl.UwbControllerSessionScopeImpl$addControlee$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
Even though before that, i receive this log:
com.example.controllerrangingapp
Creating Gms Client session scope
Upvotes: 1
Views: 383
Reputation: 43
From what I learned by building an IPS through UWB for Android, currently Android does not support connecting two phones (or devices through UWB).
I contacted Google support about that topic a while ago, and the response was vague. From what I understood, their API is there just for reference but unusable (at least for us).
On IOS it's different, you can set something like that, and it's also well documented here.
What I ended up doing, was buying external UWB devices that support multi-device communication, and implementing a sort of scheduler to handle multiple messages from multiple UWB devices. You can find the project on my GitHub. Consider this as a University project, so there can be bugs, and the code is not that clean, but you can use it as a reference if you wish to.
I guess that for multidevice UWB support, we should wait a little bit more.
Upvotes: 0