Ranging for beacons, distance same value?

Hello,

In my app I’m making I implemented a service which will first monitor for a certain beacon, when I enter the region of that beacon I start ranging. It’s actually just an app to open a door when I get near the beacon. My problem is that when I range for beacon and I call Util.computeAccuracy() 3 to 6 values I get back are exactly the same. This means that for 3 to 6 sec my distance to the beacon doesn’t change. Anyone had same kind of problem or anyone knows a fix for this? Maybe it’s something I do wrong in my code?

public void onBeaconsDiscovered(Region region, List<Beacon> list) {
            // The counter is an extra safety, the first time we go from ranging to
            // monitoring, it takes a while before our beacon is in the list that is passed
            // as a parameter to this method. To avoid clipping from ranging to monitoring,
            // we say that we have to wait 5 times before going back to monitoring.
            counter++;
            if (!list.isEmpty()) {
                counter = 0;
                Beacon nearestBeacon = list.get(0);
                Log.d(DEBUGTAG, "Distance to beacon: " + Utils.computeAccuracy(nearestBeacon));

                if (Utils.computeProximity(nearestBeacon) == Utils.Proximity.IMMEDIATE) {
                    // TODO Replace .IMMEDIATE with .NEAR
                    doRequest();
                }
            } else if (counter > 10) {
                // This means the door beacon is again out of range
                counter = 0;
                rangingToMonitoring();
            }
        }

Thanks in advance!

Debug console:

Distance to beacon: 5.670535458084814
Distance to beacon: 1.5618129043684257
Distance to beacon: 1.5618129043684257
Distance to beacon: 1.5618129043684257
Distance to beacon: 1.5618129043684257
Distance to beacon: 1.5618129043684257
Distance to beacon: 1.5618129043684257
Distance to beacon: 1.5618129043684257
Distance to beacon: 1.4231323591700062
Distance to beacon: 1.4231323591700062
Distance to beacon: 1.4231323591700062
Distance to beacon: 1.4231323591700062
Distance to beacon: 1.4231323591700062
Distance to beacon: 1.4231323591700062
Distance to beacon: 1.4231323591700062
Distance to beacon: 1.9791775637802211
Distance to beacon: 1.9791775637802211
Distance to beacon: 1.9791775637802211

We “cache” the distance values in case no new data is available. What you’re observing most likely means that only one beacon packet hits your device every ~8 seconds. (But it could also mean that the RSSI, i.e., strength with which the beacon is heard, doesn’t change.)

This might be because your device is not very responsive to Bluetooth packets (happens especially with older Android devices). You could also try decreasing the advertising interval of your beacon—by default, it’s 950 ms, which means roughly 1-second gap between sending packets. You could go down to, e.g., 200 ms, which means roughly 5 packets are sent per second, and thus it should increase responsiveness five times. (Keep in mind this is at the expense of the battery life, more packets sent per second = more energy the beacon is using = shorter battery life.)

Thanks for your answer. I already changed the advertising interval to 500ms but didn’t really helped. Indeed as you say, with my friends phone it works better. I got a Oneplus One, any known specific issues with that device? Any fix for slow Bluetooth “responsiveness”? I guess it’s a hardware problem so not really much to do.

Exactly, not much for us to do about that, as it’s usually about the hardware itself.

What kind of experience do you want to achieve with these responsive distance estimations? Maybe I’ll be able to suggest some alternative implementation.

Well, I want to open a door when I am near that door, so I first monitor for the beacon next to the door, when I enter the region I start ranging. When i get near the beacon I send a request to my server to open the door. The problem is that the values doesn’t change very quickly so when I reach the door, I wait 2-3s before my phone sends the request. I can always set a higher distance from which the request should be send but the door shouldn’t open when I’m not in front of it.

Got it. Hmm, can’t really think of any workaround for that, all my ideas are also constrained by the responsiveness of your device ):

You could try going all-in and setting adv interval to 100 ms, see if that helps?

I’ll try that, Thank you! :smile: