I am working on Android trying to search/find beacons nearby and I am using Altbeacon Android library.
The beacon is custom and here is the manufacturer specific:
//---------------flags data type------------------------------------------------
// FLAGS data type
typedef PACKED_STRUCT
{
uint8_t len; // # bytes for data type (but not including len field)
uint8_t type; // 0x01
uint8_t attrib; // 0x06
} flags_data_t;
//---------------manufacturer specific data ------------------------------------
#define BLE_MFG_SPECIFIC_DATA_TYPE 0xff
// company identifiers of interest
#define BLE_COMPANY_ID_SOMECOMPANY 0x0312
// Manufacturer specific data (msd) header
typedef PACKED_STRUCT
{
uint8_t len; // # bytes for data type (but not including len field)
uint8_t type; // 0xff for manufacturer specific
uint16_t company_id; // Bluetooth org registered company id, use Enlighted
} msd_data_header_t;
I need to get all the beacon of nearby location for this particular manufacturer.
Android code is:
beaconManager.getBeaconParsers().add(new BeaconParser() .setBeaconLayout("m:2-3=0312,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
@Override
public void onBeaconServiceConnect() {
final Region region = new Region("myBeaons", Identifier.parse(UUID), null, null);
beaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
try {
Log.d(TAG, "didEnterRegion");
beaconManager.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void didExitRegion(Region region) {
try{
Log.d(TAG, "didExitRegion");
beaconManager.stopRangingBeaconsInRegion(region);
} catch (RemoteException e) {
}}
@Override
public void didDetermineStateForRegion(int i, Region region)
{
Log.d(TAG, "didDetermineStateForRegion");
}
});
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
for (Beacon oneBeacon : beacons) {
Log.d(TAG, "distance: " + oneBeacon.getDistance() + " id:" + oneBeacon.getId1() + "/" + oneBeacon.getId2() + "/" + oneBeacon.getId3());
}
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
}
But not able to find any beacon,please suggest me how can i do this or is their any other library
The specification of the beacon format in the question doesn't give enough information. It just says that the beacon is a manufacturer advertisement that uses company code 0x0312. That's fine for a start, but it doesn't specify any other information transmitted with the advertisement.
If you really want to match any BLE advertisement sent that matches this format, you can use:
beaconManager.getBeaconParsers().add(new BeaconParser() .setBeaconLayout("m:0-1=0312,i:0-1,p:1-1"));
But this will always return 0x0312 as the first (and only) beacon identifier. And give a "dummy" measured power rating of 0x12 RSSI, which won't allow you to get accurate distance estimates. If you want to be able to read unique identifiers from the beacon and estimate the distance to it, you need to know how the beacon (if it even does) transmits its unique identifiers and measured power in the byte stream that follows the sequence described in the question.