androidbluetooth-lowenergyibeacon-androidrssibluetooth-gatt

Reading actual txPower of Android mobile


It is possible to find actual ble

txPower

of android device. So that, I can use it below Beacon builder object instead of -59 as txPower.

Beacon beacon = new Beacon.Builder()
    .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
    .setId2("1")
    .setId3("2")
    .setManufacturer(0x0118)
    .setTxPower(-59)
    .setDataFields(Arrays.asList(new Long[] {0l}))
    .build();

The use case what I have is, to read distance between two android ble device.


Solution

  • The txPower field is supposed to be the expected signal strength in dBm at 1 meter. Every Android phone model has a slightly different BLE transmitter output power, typically measuring from -50 dBm to -70 dBm at 1 meter.

    Unfortunately there is no good way to get the proper value to use for a specific Android device model unless you measure this yourself. Android has no built-in APIs to get this, and I have never seen any published specs from phone manufacturers.

    There has been renewed interest in this subject as teams develop contact tracing apps. I actually went out in a field last weekend to measure the transmitter output power of a number of devices I had handy. The Google Pixel 3a, for example, I measured -60 dBm.

    If you want to take your own measurements to help in this effort, I suggest this procedure:

    1. Go to an open area several meters away from any obstructions, particularly metal ones.
    2. Elevate the phone transmitter on a non-metal object at least one meter off the ground. The phone should be placed on end so the screen is perpindicular to the ground. (I used a camera tripod.)
    3. Run an app that transmits a beacon at full power on the phone on the tripod.
    4. Hold a reference phone (preferably an iPhone SE 1st Generation or old iPhone 4-5s) on meter away so that both screens are facing the same direction.
    5. Do a "calibration" in a beacon app like Locate Beacon to get the average RSSI over ~30 seconds.
    6. If the phone used to do the measurement is not one of the above reference models, you will need to adjust for that phone's receiver sensitivity. The spreadsheet I shared has an example of how to do that for the Pixel 3a measuring the iPhone SE. This part can be tricky as you need one other phone with a known sensitivity or transmitter power output.

    Here's my spreadsheet with the calculations: https://docs.google.com/spreadsheets/d/1-voNJAeHz78AarZmfds8WiplNhUDzeYrsW0YzKfrExU/edit?usp=sharing

    I also wrote a blog post that touches on the problem of the lack of a good data set, and tells you more than you ever wanted to know about beacon ranging.