public void onBeaconsDiscovered(Region region, final List<Beacon> beacons) {
/////////////////////////////////////////////////////////////////////////
//當RSSI<=-50,往前走
if (beacons.get(0).getRssi()<=-60){
if(beacons.get(0).getRssi()<=-60)
bt.write("f");
}
//當RSSI>=-50,往停止
if (beacons.get(0).getRssi()>=-60){
bt.write("s");
}
/////////////////////////////////////////////////////////////////////////
if (beacons != null && beacons.size() > 0) {
Log.i(TAG, "onBeaconsDiscovered");
Log.i(TAG, beacons.get(0).getName());
}
myBeacons.clear();
myBeacons.addAll(beacons);
getActionBar().setSubtitle("Found beacons: " + beacons.size());
ComparatorBeaconByRssi com = new ComparatorBeaconByRssi();
Collections.sort(myBeacons, com);
adapter.replaceWith(myBeacons);
}
我想要設定if Major=0 Minor=0 RSSI<=-60時 執行動作 要如何辦道呢?
hell
2
你可以尝试使用beaconManager.startRanging(ALL_BEACONS_REGION);
beaconManager.setRangingListener(new RangingListener() {
@Override
public void onBeaconsDiscovered(Region region,
final List<Beacon> beacons) {
for (Beacon beacon : beacons) {
if(beacon.getMajor()==0&&beacon.getMinor()==0&&beacon.getRssi()>=-60){
Log.i(TAG,"your operate");
}
}
}
});
hell
3
如果你只想识别major=0 minor=0的话 你也可以设置扫描的region
Region ALL_BEACONS_REGION = new Region(
“customRegionName”, null, 0, 0);
beaconManager.startRanging(ALL_BEACONS_REGION);
然后在onBeaconsDiscovered中判断rssi
那如果我要寫
如果 Major=0 Minor=0 的RSSI值 >-20 Major=1 Minor=1 的RSSI值
我要寫A的RSSI值 大於 B的RSSI值 -20時執行動作的話怎麼寫~
如果用大於小於 難寫的話 加減法也是可以 但是該如何判斷呢?
hell
5
int rssi00;
int rssi11;
for (Beacon beacon : beacons) {
if(beacon.getMajor()==0&&beacon.getMinor()==0){
rssi00 = beacon.getRssi();
}else if(beacon.getMajor()==1&&beacon.getMinor()==1){
rssi11 = beacon.getRssi();
}
}
if((rssi00-20)>rssi11){
Log.i(TAG,“your operate”);
}
hell
7
上面是比较的一个参考 没太明白你大小比较的逻辑
你是不是要比较rssi00-rssi11>-20.
對就是rssi00>rssi11 -5的話 執行動作
現在難題來了 要如何設定優先權呀~
rssi00 大於小於 rssi11 可以設定為搶先嗎?
因為原本rssi00 的RSSI <-60的時候 會執行bt.write(“f”);
rssi00 的RSSI >-60的時候 會執行bt.write(“s”);
要如何增加rssi00 大於小於 rssi11條件時搶先執行3秒
int rssi00 = 0;
int rssi11 = 1;
for (Beacon beacon : beacons) {
if(beacon.getMajor()==0&&beacon.getMinor()==0){
rssi00 = beacon.getRssi();
}else if(beacon.getMajor()==1&&beacon.getMinor()==1){
rssi11 = beacon.getRssi();
}
}
if((rssi00-5)<rssi11){
bt.write("d");
}
修改了
int rssi00 = 0;
int rssi11 = 1;
沒有=0 =1的話if((rssi00-5)<rssi11)會出錯
控制自走車的方向
當rssi<-60 時 前進
當rssi>-60 時 停止
當rssi00 大於小於 rssi11 時 左右轉
但是我剛剛寫在一起沒有反應~
應該是沒有搶先的關西?