0

So I have been learning about beacons recently, I was trying to develop an application that scans beacons around me and get their url, I seem to have a trouble understanding what layout for beacon should I choose, should it be EDDYSTONE_URL, and if so, how should I retrieve this url in android app, here's what I have done:

    public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
    for (Beacon beacon : beacons) {
        if (!rangingMessageRaised && beacon.getServiceUuid() == 0xfeaa) {
            // This is a Eddystone-UID frame
            Identifier namespaceId = beacon.getId1();
            Identifier instanceId = beacon.getId2();
            String url = UrlBeaconUrlCompressor.uncompress(beacon.getId1().toByteArray());
            showAlert(TAG, "I see a beacon transmitting a url: " + url +
                    " approximately " + beacon.getDistance() + " meters away.");


            if (beacon.getExtraDataFields().size() > 0) {
                long telemetryVersion = beacon.getExtraDataFields().get(0);
                long batteryMilliVolts = beacon.getExtraDataFields().get(1);
                long pduCount = beacon.getExtraDataFields().get(3);
                long uptime = beacon.getExtraDataFields().get(4);

                Log.d(TAG, "The above beacon is sending telemetry version " + telemetryVersion +
                        ", has been up for : " + uptime + " seconds" +
                        ", has a battery level of " + batteryMilliVolts + " mV" +
                        ", and has transmitted " + pduCount + " advertisements.");

            }
        }
    }
    rangingMessageRaised=true;
}

Code for setting up beacon layout:

    // Detect the URL frame:


beaconManager.getBeaconParsers().add(new BeaconParser().
             setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
beaconManager.bind(this);

The identifier I used for EDDYSTONE_URL is when creating beacon region is :

try {
    beaconRegion = new
    Region("MyBeacons", null,null,null);
    //I initially wrote this for EDDYSTONE_UID 
    //which seems to work for getting UID 
    // And distance but not url

    //Identifier myBeaconNamespaceId =  
    //Identifier.parse("0x2f234454f4911ba9ffa6");
    // Identifier myBeaconInstanceId
    //Identifier.parse("0x000000000001");
    //  Region region = new Region("my- beacon-region", myBeaconNamespaceId, myBeaconInstanceId, null);
    beaconManager.startMonitoringBeaconsInRegion(beaconRegion);
    beaconManager.startRangingBeaconsInRegion(beaconRegion);
        } catch (RemoteException e) {
        e.printStackTrace();
      }
    }

The output I am getting for the the beacon layout EDDYSTONE_URL is:

"I see a beacon transmitting a url: DT∆ws#2 approximately 0.00969 meters away".

The url seems to be encoded or giving a very weird value, maybe it's the problem with the beacon.getId1() that I am applying url decompressor on.

Ali Abbas
  • 97
  • 7
  • Please show the setup code you use to start ranging (e.g. calls to `startRangingBeaconsInRegion`) as well as any calls you make to add a `BeaconParser`. Also please describe what results you see. Do you get any callbacks to `didRangeBeaconsInRegion`? If so, what parts of your code execute in that method? Finally, please tell me how you know your beacon is transmitting a URL. Have you tested it with an off the shelf scanner app and seen the URL? – davidgyoung Aug 03 '19 at 17:27
  • I have added the code and output you asked for, I am just a bit confused with getting the url from beacons, maybe I am not using the correct identifier for the url, btw I am using Minew Beacon E8 which supports Eddystone protocol and since I am able to get the UID and distance, I think I am missing out on a very smalll thing. – Ali Abbas Aug 04 '19 at 06:47
  • If you use the BeaconScope app from the Google Play Store, does if see the transmission as Eddystone URL and does it decide the URL properly? – davidgyoung Aug 04 '19 at 12:48

0 Answers0