B4A Class [IoT] BeaconParser - Discover iBeacons and Eddystone beacons

The BeaconParser class parses the advertising data that is sent by BLE beacons.
It supports iBeacons, Eddystone UID and Eddystone URL formats.

Note that this class is also compatible with B4i. However it will not detect iBeacons due to the way those beacons are handled in iOS.

You do not need to connect to the beacon. All the important information is delivered in the advertising data.
Call BleManager2.Scan2(Null, True) to start scanning. The second parameter (AllowDuplicates) means that it will "find" the same devices again and again.

B4A example:

upload_2015-12-7_13-4-49.png


B4i example:

upload_2015-12-7_13-5-13.png


The distance is not accurate enough to be useful.

The main method of BeaconParser is Parse. You should call it from the DeviceFound sub:
B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
   Dim beacon1 As Beacon = Parser.Parse(AdvertisingData, RSSI)
   If beacon1 <> Null Then
    'a beacon was discovered.
    'find the beacon type based on the BeaconType field.
  Select beacon1.BeaconType
     Case Parser.TypeiBeacon
       Dim ib As iBeacon = beacon1.SpecificData
       Log($"iBeacon: ${ib.uuid} (${ib.major}/${ib.minor})"$)
     Case Parser.TypeEddystoneUID
       Dim euid As EddystoneUID = beacon1.SpecificData
       lLog($"Eddystone UID: ${euid.Namespace}:${euid.Instance}"$)
     Case Parser.TypeEddystoneURL
       Dim eurl As EddystoneURL = beacon1.SpecificData
      Log($"Eddystone URL: ${eurl.url}"$)
   End Select
   End If
End Sub

New version of BeaconParser was uploaded. It requires BLE v1.20+: https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/#post-377705

It fixes an issue when there are multiple records with the same type.
 

Attachments

  • BeaconParser_B4i.zip
    7.2 KB · Views: 680
  • BeaconParser_B4A.zip
    7.3 KB · Views: 872
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
Erel, that is great news! No we can discover both beacon versions with one app.

BTW, what is the $ symbol for?
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Thank you for the link. I have tried the App and...

  • not compatible with my Galaxy S5
  • compatible with my GalaxyTab 10 (2014 model) :)

but the advertising function does not work :(
 

jazzzzzzz

Active Member
Licensed User
Longtime User
@Erel Galaxy tab10.1 with kikat works good with this class, but with same beacon in htc one m8 with marshmallow beacons are showing just for 5 sec and then goes from the list

is there some permission issue with this class on android 6.0?

https://play.google.com/store/apps/details?id=com.radiusnetworks.locate&hl=en

Above app from radius networks work good on the same HTC One M8 with Android 6.0 Marshmallow. So I think there is some issue here.Please verify it
 
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
For some reason all other apps. can find the Eddystone (Kontakt.io) beacons but not the parser. I think something is wrong in below code:

If CompareBytes(b, Array As Byte(0xAA, 0xFE), 0) Then
 

bluedude

Well-Known Member
Licensed User
Longtime User
It returns 0DD0506F3057333164 hex value and I'm 100% sure it is an Eddystone beacon made by Kontakt.io.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Kontak.io sells certified Beacons and this is a big beacon supplier. All other beacon apps. I use recognize these beacons. So it seems something else is wrong with the parser code.

I know the specification.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Attached the same beacons in another app. (screenshot). All beacons recognized.
 

Attachments

  • beacons.png
    beacons.png
    110.2 KB · Views: 539

bluedude

Well-Known Member
Licensed User
Longtime User
Hi, below the response from Kontakt.io. I think they are right.

"I've talked with our engineers and they can't imagine that our beacon does not broadcast this part of the frame. This is a required element and without it no app would be able to discover our beacons as Eddystone beacons, and until now we haven't had such problem.

Would it be possible to send us screenshots or something like that showing this "broken" advertising packet? What software and hardware do you use to read the raw data? Is it happening only on your device Po0W or some other beacons?"
 

bluedude

Well-Known Member
Licensed User
Longtime User
Ok, will try. All other apps i tested show the Eddystone beacons out of the box so something is fishy.
 

bluedude

Well-Known Member
Licensed User
Longtime User
This is what I get:

0201060303AAFE1516AAFE00EEF7826DA6BC5B71E0893E506F3057696F08094B6F6E74616B74020A040A160DD0506F305733316400000000000000000000

This Eddystone device is configured with an URL: www.things.io

I notice that the AAFE is in key 3 so i'm checking for that right now too. I haven't discovered the URL in the package yet.
 
Top