4

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.

GianhTran
  • 3,443
  • 2
  • 22
  • 42
  • 1
    Related: [Estimating beacon proximity/distance based on RSSI - Bluetooth LE](https://stackoverflow.com/q/22784516/295004) and [Understanding ibeacon distancing](https://stackoverflow.com/q/20416218/295004) – Morrison Chang Jun 30 '20 at 05:22
  • 1
    For someone who faces this situation, I think some device, I means the manufacturer, don't expose `txPower` in `ScanResult`.so still haven't another solution to fix this – GianhTran Dec 07 '20 at 09:27
  • No solutions yet? – Edw590 Jul 24 '21 at 23:50

0 Answers0