Getting Packet Data Transferred From Ibeacon Android
Solution 1:
If you simply want to get the bytes of the packet to be transmitted, you can do so like this:
Beaconbeacon=newBeacon.Builder()
.setId1("6fb0e0e9-2ae6-49d3-bba3-3cb7698c77e2")
.setId2(Integer.toString(minor1))
.setId3(Integer.toString(minor2))
.setManufacturer(0x0000)
.setTxPower(-59)
.setDataFields(Arrays.asList(newLong[] {0l}))
.build();
BeaconParserbeaconParser=newBeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
byte[] bytes = p.getBeaconAdvertisementData(beacon);
Using the code above, the array of bytes will look like this:
02156f b0 e0 e9 2a e6 49 d3 bb a3 3c b7 698c77 e2 ...
Note that this byte array isn't the full packet that is transmitted over the air, just the manufacturer data part of it. The packet transmitted over the air is prefixed with a PDU type byte and a length byte, and is also prefixed with a flags PDU. These prefixes, however, are the same for every packet transmitted, and are added automatically by Androids BLE transmission APIs, so they are not included in the bytes returned by getBeaconAdvertisementData()
.
Solution 2:
Assuming that you are going to receive the transmitted data on some Android Device, you could use the same library to do that.
This is how the flow would be,
@OverridepublicvoidonCreate(Bundle bundle){
...
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(newBeaconParser().
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
...
}
@OverridepublicvoidonBeaconServiceConnect() {
/**
* Start Monitoring the relevant region.
* */try {
beaconManager.startMonitoringBeaconsInRegion(newRegion("Generic_Region", null,
null, null));
}
catch (RemoteException e){
e.printStackTrace();
}
beaconManager.addMonitorNotifier(newMonitorNotifier() {
/**
* Start ranging for Beacons when a region is entered.
* */@OverridepublicvoiddidEnterRegion(Region region) {
try {
beaconManager.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
}
/**
* Stop ranging for Beacons on region exit.
* */@OverridepublicvoiddidExitRegion(Region region) {
try {
beaconManager.stopRangingBeaconsInRegion(region);
}
catch (RemoteException e) {
e.printStackTrace();
}
Log.i(TAG, "SERVICE : I no longer see a beacon");
}
@OverridepublicvoiddidDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "SERVICE : I have just switched from seeing/not seeing beacons: " + state);
}
});
beaconManager.addRangeNotifier(newRangeNotifier() {
@OverridepublicvoiddidRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
}
});
}
Post a Comment for "Getting Packet Data Transferred From Ibeacon Android"