0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
user
  • 471
  • 2
  • 16
  • 31

1 Answers1

1

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.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • not working ----Logcat output :- BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5 – user Jul 27 '16 at 18:45
  • Try adding `beaconManager.setDebug(true)` and capturing the logcat output, specifically lines that look like this: `09-10 15:46:02.577: D/BeaconParser(11355): This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 0201061aff4c000215078701d2fa844b429c161417dabc159d00010001c20000000000000000000000000000000000000000000000000000000000000000` – davidgyoung Jul 27 '16 at 18:48
  • nParser: Ignoring pdu type 01 07-27 11:52:03.978 10294-10378/com.enlighted D/BeaconParser: Processing pdu type FF: 0201041aff4c000215441651aa403611e6beb89e71128cae770012815ab20000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29 07-27 11:52:03.978 10294-10378/com.enlighted D/BeaconParser: This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 0201041aff4c000215441651aa403611e6beb89e71128cae770012815ab20000000000000000000000000000000000000000000000000000000000000000 – user Jul 27 '16 at 18:54
  • The bytes from the logs don't match those described in the question. Try using a beacon parser for a standard iBeacon. http://stackoverflow.com/questions/32513423/android-altbeacon-library-how-to-find-the-beacon-layout – davidgyoung Jul 27 '16 at 19:07
  • Locate app showing No visible beacons. can you please tell me how to use Beacon parser for standard iBeacon.i need very urgent – user Jul 27 '16 at 19:16
  • See link in my last comment – davidgyoung Jul 27 '16 at 19:17
  • This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 0201041aff4c000215441651aa403611e6beb89e71128cae77001287d5b20000000000000000000000000000000000000000000000000000000000000000 07-27 12:19:08.109 12623-12741/com.enlighted D/BeaconParser: Processing pdu type FF: 0201041aff35030215020000f7064701e2f90000000000000001000117b20000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29, .using IBEACON parser setBeaconLayout("m:2-3=0312,i:4-19,i:20-21,i:22-23,p:24-24") – user Jul 27 '16 at 19:23
  • Able to detect beacon this is logcat output:-r: Processing pdu type FF: 0201041aff4c000215441651aa403611e6beb89e71128cae7700128656b20000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29 07-27 12:34:23.240 1309-1386/com.enlighted D/BeaconParser: This is a recognized beacon advertisement -- 02 15 seen ..is this correct ? – user Jul 27 '16 at 19:36
  • "This is a recognized beacon advertisement" is what you want to see, yes. That means it is detecting the beacon. You should be able to get ranging and monitoring callbacks if using the APIs per the documentation. – davidgyoung Jul 27 '16 at 20:28
  • Okay. How to get UUIDs of beacons currently i am using static UUID which i found using anothor application form play store,i want to get dynamically for all beacons – user Jul 27 '16 at 20:34