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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Dec 7, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    Sub Manager_DeviceFound (Name As StringId 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.
     

    Attached Files:

    Last edited: Sep 20, 2018
  2. bluedude

    bluedude Well-Known Member Licensed User

    Erel, that is great news! No we can discover both beacon versions with one app.

    BTW, what is the $ symbol for?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

  4. bluedude

    bluedude Well-Known Member Licensed User

    Ah ok, missed that feature.
     
  5. freedom2000

    freedom2000 Well-Known Member Licensed User

    Thank you for this class. I have just ordered a HM-10 chip to play with HM10 e-beacons

    By the way, I have also read that it could be possible to turn an android into an ibeacon.
    Is this possible with B4A ? (see end of this page)
     
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. freedom2000

    freedom2000 Well-Known Member Licensed 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 :(
     
  8. jazzzzzzz

    jazzzzzzz Active Member Licensed 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: Feb 13, 2016
  9. Erel

    Erel Administrator Staff Member Licensed User

    It is not related to Android 6.0.

    You will need to debug it and see what happens.

    You can also change TIME_TO_LIVE_SECONDS to a larger value.
     
    luke2012 likes this.
  10. bluedude

    bluedude Well-Known Member Licensed 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
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Check the value of b:
    Code:
    Dim bc As ByteConverter
    Log(bc.HexFromBytes(b))
     
  12. bluedude

    bluedude Well-Known Member Licensed User

    It returns 0DD0506F3057333164 hex value and I'm 100% sure it is an Eddystone beacon made by Kontakt.io.
     
  13. Erel

    Erel Administrator Staff Member Licensed User

  14. bluedude

    bluedude Well-Known Member Licensed 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.
     
  15. bluedude

    bluedude Well-Known Member Licensed User

    Attached the same beacons in another app. (screenshot). All beacons recognized.
     

    Attached Files:

  16. bluedude

    bluedude Well-Known Member Licensed 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?"
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    You can see the parser code. Try to modify it to print all the advertising data. Maybe the relevant data is stored in a different key.

    I tested it here with Eddystone beacons and it worked. If you like you can send me such beacon by mail and I'll test it here.
     
  18. bluedude

    bluedude Well-Known Member Licensed User

    Ok, will try. All other apps i tested show the Eddystone beacons out of the box so something is fishy.
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Please copy the attached jar to the additional libraries folder. The change in this jar is that it adds the full advertising raw data to the map with key = 0.
    Post the output of Log(nc.HexFromString(AdvertisingData.Get(0)))
     

    Attached Files:

    Last edited: Apr 5, 2016
  20. bluedude

    bluedude Well-Known Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice