MokoBeaconX / MokoBeaconX_Android

Android Studio Platform
10 stars 11 forks source link

getDistance function #4

Open nvchung opened 5 years ago

nvchung commented 5 years ago

I want to get a distance from device to the beacon, I find getDistance function in com.moko.support.utils.MokoUtils but dont know how to use? Pls help!

johanromuald commented 4 years ago

Hi,

Is this correct?

Do I have to pass the rangingData as int?

import com.moko.support.utils.MokoUtils;

Double distance = MokoUtils.getDistance(rssi, rangingData);

Thank you

liuwenzheng commented 4 years ago

Yes, the rangeingData must be a positive integer

johanromuald commented 4 years ago

Hi, Thank you. For Eddystone UUID the rangingdata will be; int txPower = Integer.parseInt(data.substring(2, 4), 16);

Can you please confirm. Thank you. JR

johanromuald commented 4 years ago

Sorry for not clear. To save battery I am only using one Slot EddyStone format UUID.

Hence, according following class;

public class BeaconXUID implements Serializable { public String rangingData; public String namespace; public String instanceId; }

and following class

public class BeaconXParser {

public static BeaconXUID getUID(String data) {
    BeaconXUID uid = new BeaconXUID();
    int txPower = Integer.parseInt(data.substring(2, 4), 16);
    uid.rangingData = (byte) txPower + "";
    uid.namespace = data.substring(4, 24);
    uid.instanceId = data.substring(24, 36);
    return uid;
}

The rangingdata = int txPower. Am I right?

liuwenzheng commented 4 years ago

Yes, you are right.

johanromuald commented 4 years ago

Thank you very much for your help.

Miteshmakwana73 commented 4 years ago

@johanromuald how do you get distance? have you got a solution? which parameter should i pass to get distance from BeaconXListAdapter class

johanromuald commented 3 years ago

if(txPower >0) { Double Tdistance = (MokoUtils.getDistance(beaconXInfo.rssi, txPower)) / 1000; String Sdistance= String.valueOf( Tdistance); distance = Sdistance.substring(0,4); }

It is not reliable as RSSI varies rapidly. You have to come with some kind filter or running average RSSI to do this.

Miteshmakwana73 commented 3 years ago

@johanromuald getting multiple txpower in list so not getting distance