i working on app creates messages on entering different regions based on range beacon (e.g. position < .5 | position < 2 | position < 10). experienced weird behavior while logging distance , rssi. replacing rssi last received rssi if 127. value seems out of place.
the problem
05-08 10:09:48.379 21495-22283 i/rangingservice? rssi: 127 distance: 2533.712149492241 meters 05-08 10:09:49.500 21495-22284 i/rangingservice? rssi: -38 distance: 0.07068384635393776 meters 05-08 10:09:50.662 21495-22301 i/rangingservice? rssi: 127 distance: 0.07068384635393776 meters 05-08 10:09:51.795 21495-22302 i/rangingservice? rssi: 127 distance: 2533.712149492241 meters 05-08 10:09:52.946 21495-22318 i/rangingservice? rssi: -34 distance: 0.10971085339590038 meters 05-08 10:09:54.074 21495-22327 i/rangingservice? rssi: 127 distance: 0.10971085339590038 meters 05-08 10:09:55.375 21495-22404 i/rangingservice? rssi: 127 distance: 2533.712149492241 meters 05-08 10:09:56.499 21495-22488 i/rangingservice? rssi: -36 distance: 0.08827424889527898 meters 05-08 10:09:57.637 21495-22492 i/rangingservice? rssi: -36 distance: 0.008486821580451052 meters 05-08 10:09:58.771 21495-22493 i/rangingservice? rssi: 127 distance: 0.08827424889527898 meters 05-08 10:09:59.902 21495-22509 i/rangingservice? rssi: 127 distance: 2533.712149492241 meters
if @ distance, randomly spike every calculation after or rssi of 127. don't understand why rssi 127 randomly often. ideas?
the workaround
int rssi2use = beacon.getrssi(); if (rssi2use == 127) { log.i(tag, "using last rssi " + lastrssi + " instead of 127"); rssi2use = lastrssi; } else { lastrssi = beacon.getrssi(); }
mybeacon.java simplification of distance calulation clean out averages of rssis
public class mybeacon extends beacon { private static final string tag = mybeacon.class.getsimplename(); private final beacon beacon; private final int rssi2use; public mybeacon(final beacon beacon, int rssi2use) { this.beacon = beacon; this.rssi2use = rssi2use; } @override public double getdistance() { return mdistance = calculatedistance(beacon.gettxpower(), rssi2use); } public beacon getsuperbeacon() { return beacon; } }
rangingservice.java
@override public void oncreate() { super.oncreate(); log.d(tag, "service oncreate"); beaconmanager.setdebug(true); rangedbeacon.setsampleexpirationmilliseconds(2200); beaconmanager = beaconmanager.getinstanceforapplication(this); beaconmanager.bind(this); }
i listen 1 speficic beacon.
@override public void onbeaconserviceconnect() { beaconmanager.setrangenotifier(new rangenotifier() { @override public void didrangebeaconsinregion(collection<beacon> beacons, region region) { if (beacons.size() == 1) { beacon beacon = beacons.iterator().next(); handlebeaconinrange(beacon); } } }); try { beaconmanager.startrangingbeaconsinregion(new region(range_region_id, null, null, null)); } catch (remoteexception e) { log.e(tag, "exception on onbeaconserviceconnect", e); } }
there's more handlebeaconinrange() reacts different distances, produces log.
private void handlebeaconinrange(beacon beacon) { int rssi2use = beacon.getrssi(); if (rssi2use == 127) { log.i(tag, "using last rssi " + lastrssi + " instead of 127"); rssi2use = lastrssi; } else { lastrssi = beacon.getrssi(); } mybeacon mybeacon = new mybeacon(beacon, rssi2use); double distance = mybeacon.getdistance(); log.i(tag, "rssi: " + rssi2use + " distance: " + distance + " meters"); }
the log:
05-08 09:25:47.675 27646-29040/ i/rangingservice? using last rssi -56 instead of 127 05-08 09:25:47.675 27646-29040/ i/rangingservice? rssi: -56 distance: 0.7040448636262671 meters 05-08 09:25:48.839 27646-29041/ i/rangingservice? rssi: -56 distance: 0.7040448636262671 meters 05-08 09:25:49.982 27646-29042/ i/rangingservice? rssi: -58 distance: 0.97085 meters 05-08 09:25:51.121 27646-29043/ i/rangingservice? using last rssi -58 instead of 127 05-08 09:25:51.121 27646-29043/ i/rangingservice? rssi: -58 distance: 0.97085 meters 05-08 09:25:52.263 27646-29044/ i/rangingservice? using last rssi -58 instead of 127 05-08 09:25:52.263 27646-29044/ i/rangingservice? rssi: -58 distance: 0.97085 meters 05-08 09:25:53.408 27646-29045/ i/rangingservice? rssi: -55 distance: 0.5879588872684474 meters 05-08 09:25:54.575 27646-29046/ i/rangingservice? using last rssi -55 instead of 127 05-08 09:25:54.575 27646-29046/ i/rangingservice? rssi: -55 distance: 0.5879588872684474 meters 05-08 09:25:55.701 27646-29047/ i/rangingservice? rssi: -54 distance: 0.4893928979531776 meters 05-08 09:25:56.858 27646-29064/ i/rangingservice? rssi: -61 distance: 1.1474711863884917 meters 05-08 09:25:57.991 27646-29074/ i/rangingservice? using last rssi -61 instead of 127 05-08 09:25:57.992 27646-29074/ i/rangingservice? rssi: -61 distance: 1.1474711863884917 meters 05-08 09:25:59.130 27646-29075/ i/rangingservice? rssi: -46 distance: 0.09846874009910023 meters 05-08 09:26:00.247 27646-29081/ i/rangingservice? using last rssi -46 instead of 127 05-08 09:26:00.247 27646-29081/ i/rangingservice? rssi: -46 distance: 0.09846874009910023 meters 05-08 09:26:01.392 27646-29085/ i/rangingservice? rssi: -49 distance: 0.18521700814366415 meters 05-08 09:26:02.534 27646-29086/ i/rangingservice? using last rssi -49 instead of 127 05-08 09:26:02.534 27646-29086/ i/rangingservice? rssi: -49 distance: 0.18521700814366415 meters 05-08 09:26:03.680 27646-29087/ i/rangingservice? using last rssi -49 instead of 127 05-08 09:26:03.680 27646-29087/ i/rangingservice? rssi: -49 distance: 0.18521700814366415 meters 05-08 09:26:04.823 27646-29088/ i/rangingservice? rssi: -33 distance: 0.0035551625558338114 meters 05-08 09:26:05.967 27646-29089/ i/rangingservice? rssi: -37 distance: 0.011161878866100936 meters
this not related library. seems related used device, either firmware or adapter spitting out wrong readings.
thank @davidgyoung helping clearing this.
Comments
Post a Comment