Calculate distance using Android BLE (Bluetooth low energy)

Viewed 262

I tried to get distance between two mobile devices using BLE, I known that is a common task, and we can using RSSI and txPower to find out the distance.

But I have a problem to get txPower value in android BLE. It's always return 127 (TX_POWER_NOT_PRESENT), although I already add it in AdvertiseData

val data = AdvertiseData.Builder().setIncludeDeviceName(false).setIncludeTxPowerLevel(true)
            .addServiceUuid(pUuid).build() 

Below is code block using to get txPower

private fun processScanResult(scanResult: ScanResult?) {

            var txPower: Int? = null

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                txPower = scanResult?.txPower
                if (txPower == 127) {
                    txPower = null
                }
            }
        }

Does anyone have a suggestion for my issue? Any response would be appreciated.

0 Answers
Related