Estimating beacon proximity/distance based on RSSI - Bluetooth LE

前端 未结 4 1656
独厮守ぢ
独厮守ぢ 2020-11-29 16:40

I\'ve got a simple iOS app which displays the proximity of the Bluetooth LE beacons it detects using such expressions as \"immediate\", \"near\" etc. and I need to write som

4条回答
  •  有刺的猬
    2020-11-29 17:30

    It is unclear whether your inability to read the "txPower" or "measuredPower" calibration constant is due to the AdRecord class or due to the information being missing from the advertisements you are trying to parse. It doesn't look to me like that class will parse a standard iBeacon advertisement. Either way, there is a solution:

    SOLUTION 1: If your beacons send a standard iBeacon advertisement that includes the calibration constant, you can parse it out using code in the open source Android iBeacon Library's IBeacon class here.

    SOLUTION 2: If your beacons DO NOT send a standard iBeacon advertisement or do not include a calibration constant:

    You must hard-code a calibration constant in your app for each device type you might use. All you really need from the advertisement to estimate distance is the the RSSI measurement. The whole point of embedding a calibration constant in the transmission is to allow a wide variety of beacons with quite different transmitter output power to work with the same distance estimating algorithm.

    The calibration constant, as defined by Apple, basically says what the RSSI should be if your device is exactly one meter away from the beacon. If the signal is stronger (less negative RSSI), then the device is less than one meter away. If the signal is weaker (more negative RSSI), then the device is over one meter away. You can use a formula to make a numerical estimate of distance. See here.

    If you aren't dealing with advertisements that contain a "txPower" or "measuredPower" calibration constant, then you can hard-code a lookup table in your app that stores the known calibration constants for various transmitters. You will first need to measure the average RSSI of each transmitter at one meter away. You'll then need some kind of key to look up these calibration constants in the table. (Perhaps you can use the some part of the string from the AD structure, or the mac address?) So your table might look like this:

    HashMap txPowerLookupTable = new HashMap();
    txPowerLookupTable.put("a5:09:37:78:c3:22", new Integer(-65));
    txPowerLookupTable.put("d2:32:33:5c:87:09", new Integer(-78));
    

    Then after parsing an advertisement, you can look up the calibration constant in your onLeScan method like this:

    String macAddress = device.getAddress();
    Integer txPower = txPowerLookupTable.get(macAddress);
    

提交回复
热议问题