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

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

  1. dataware

    dataware Member Licensed User

    its working perfect, Tnks =)
     
  2. Christian García S.

    Christian García S. Active Member Licensed User

    Hi everybody, I have an issue.

    I just implemented ebeacon parser in B4A without issues, its works perfectly.

    now I want to implement in B4I and I have an issue, I received log with error:

    Application_Start
    Application_Active
    Error occurred on line: 88 (BeaconParser)
    Out of bounds. Index=0 Length=0
    Stack Trace: (
    CoreFoundation <redacted> + 152
    libobjc.A.dylib objc_exception_throw + 38
    CoreFoundation <redacted> + 0
    BLE Example -[B4IArray getByteFast:] + 238
    BLE Example -[b4i_beaconparser _parseeddystone::::] + 1112
    CoreFoundation <redacted> + 68
    CoreFoundation <redacted> + 300
    BLE Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
    BLE Example -[B4IShell runMethod:] + 574
    BLE Example -[B4IShell raiseEventImpl:method:args::] + 2212
    BLE Example -[B4IShellBI raiseEvent:event:params:] + 1442
    BLE Example +[B4IDebug delegate:::] + 52
    BLE Example -[b4i_beaconparser _parse:::] + 524
    BLE Example -[b4i_main _manager_devicefound::::] + 904
    CoreFoundation <redacted> + 68
    CoreFoundation <redacted> + 300
    BLE Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
    BLE Example -[B4IShell runMethod:] + 574
    BLE Example -[B4IShell raiseEventImpl:method:args::] + 2212
    BLE Example -[B4IShellBI raiseEvent:event:params:] + 1442
    BLE Example +[B4IObjectWrapper raiseEvent:::] + 220
    BLE Example -[BleDelegate centralManager:didDiscoverPeripheral:advertisementData:RSSI:] + 508
    CoreBluetooth <redacted> + 906
    CoreBluetooth <redacted> + 638
    CoreBluetooth <redacted> + 84
    CoreBluetooth <redacted> + 50
    libdispatch.dylib <redacted> + 10
    libdispatch.dylib <redacted> + 22
    libdispatch.dylib <redacted> + 854
    libdispatch.dylib <redacted> + 886
    libdispatch.dylib _dispatch_main_queue_callback_4CF + 596
    CoreFoundation <redacted> + 8
    CoreFoundation <redacted> + 848
    CoreFoundation CFRunLoopRunSpecific + 470
    CoreFoundation CFRunLoopRunInMode + 104
    GraphicsServices GSEventRunModal + 80
    UIKit UIApplicationMain + 150
    BLE Example main + 108
    libdyld.dylib <redacted> + 2
    )

    The beacon is a ibeacon not an eddystone, I have B4I version 3.60 and the BLE 2.0 thats includes this version.

    Later I uncomment this lines:

    For Each key As Int In AdvertisingData.Keys
    Log($"${key}= ${bc.HexFromBytes(AdvertisingData.Get(key))}"$)
    Next

    And I get this:

    Cannot parse: kCBAdvDataServiceData

    Thanks a lot for your help.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this in B4i questions forum.
     
  4. Hypnos

    Hypnos Active Member Licensed User


    Hi All,

    I want to use a raspberry pi to monitor my beacons instead of an android phone, so I tried to install this example in Raspberry Pi 3 for some test (Android Things platform)

    I got the following error, is that error mean that I can't use BLE in Things platform yet?

    Thanks!

    Code:
    *** Service (starter) Create ***
    ** 
    Service (starter) Start **
    ** 
    Activity (main) Create, isFirst = true **
    starter_scan (java line: 
    208)
    java.lang.RuntimeException: Error starting scan.
        at anywheresoftware.b4a.objects.BleManager2.Scan2(BleManager2.java:
    142)
        at b4a.example.starter._scan(starter.java:
    208)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    186)
        at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:
    1044)
        at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:
    978)
        at b4a.example.main._btnscan_click(main.java:
    373)
        at b4a.example.main._activity_create(main.java:
    343)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    186)
        at b4a.example.main.afterFirstLayout(main.java:
    102)
        at b4a.example.main.access$
    000(main.java:17)
        at b4a.example.main$WaitForLayout.run(main.java:
    80)
        at android.os.Handler.handleCallback(Handler.java:
    751)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    154)
        at android.app.ActivityThread.main(ActivityThread.java:
    6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    865)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    755)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this.
     
  6. Christian García S.

    Christian García S. Active Member Licensed User

    Hi everybody, I would like to know if I can put ebeacon parser as a service at startup like starter service (service create or service start) , this means that it is not necessary to have the app open and I can detect the ebeacons, something like ebeacon monitoring in iOS.

    Thanks,

    Christian
     
    Last edited: Sep 13, 2017
  7. freedom2000

    freedom2000 Well-Known Member Licensed User

    Hi,

    Yes you can it works in a service
     
  8. Christian García S.

    Christian García S. Active Member Licensed User

    Thanks freedom2000 for you response.

    I put:

    Code:
    Sub Service_Create
        manager.Initialize(
    "manager")
        beacons.Initialize
    '    Timer1.Initialize("timer1", TIME_TO_LIVE_SECONDS * DateTime.TicksPerSecond)
    '    Timer1.Enabled = True
        Parser.Initialize
        CallSubDelayed(FirebaseMessaging, 
    "SubscribeToTopics")
       
        Globals.IniDB
        Globals.CreateTables
        Globals.vDeviceid = Globals.GetDeviceId
        
    Log("Device: " & Globals.vDeviceid)       
    End Sub
    and:

    Code:
    Sub Service_Start (StartingIntent As Intent)
        manager.Scan2(
    NullTrue)   
    End Sub
    But I dont receive information from beacon, can you give more information about where or how I put the code.

    Thanks for your help

    Christian
     
  9. Christian García S.

    Christian García S. Active Member Licensed User

    Hello everyone,

    I am keep trying about read beacons like a service, but I failed, I dont know how I can do.

    And now y have reports from some customers with application block.

    I put this code in service -> starter

    Code:
    Sub Process_Globals
        
    Public manager As BleManager2
        
    Public Parser As BeaconParser

        
    Public beacons As Map
        
    Public const TIME_TO_LIVE_SECONDS As Int = 5   
    End Sub

    Sub Service_Create
        manager.Initialize(
    "manager")
        beacons.Initialize
        Parser.Initialize
       
        Globals.IniDB
        Globals.CreateTables
    End Sub

    Sub Service_Start (StartingIntent As Intent)
        manager.Scan2(
    NullTrue)
    End Sub

    Public Sub Scan
        manager.Scan2(
    NullTrue)
        scanning = 
    True
    End Sub
    I check report in google app developer and I got these errors:

    Code:
    java.lang.RuntimeException:
      at anywheresoftware.b4a.objects.BleManager2.Scan2 (BleManager2.java:
    142)
      at com.creator.app.starter._service_start (starter.java:
    370)
      at java.lang.reflect.Method.invoke (Native Method)
      at java.lang.reflect.Method.invoke (Method.java:
    372)
      at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:
    186)
      at anywheresoftware.b4a.BA.raiseEvent (BA.java:
    166)
      at com.creator.app.starter.handleStart (starter.java:
    105)
      at com.creator.app.starter.access$
    000 (starter.java:8)
      at com.creator.app.starter$
    1.run (starter.java:70)
      at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (ServiceHelper.java:
    105)
      at com.creator.app.starter.onStartCommand (starter.java:
    68)
      at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:
    3958)
      at android.app.ActivityThread.access$
    2300 (ActivityThread.java:218)
      at android.app.ActivityThread$H.handleMessage (ActivityThread.java:
    1842)
      at android.os.Handler.dispatchMessage (Handler.java:
    102)
      at android.os.Looper.loop (Looper.java:
    145)
      at android.app.ActivityThread.main (ActivityThread.java:
    7007)
      at java.lang.reflect.Method.invoke (Native Method)
      at java.lang.reflect.Method.invoke (Method.java:
    372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:
    1404)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:
    1199)
    And I got this error too:

    Thanks for your help.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread in the questions forum.
     
  11. Christian García S.

    Christian García S. Active Member Licensed User

    Hello everyone,

    I have an issue con beacon parser when I have ebeacon and eddystone and the same time, the app crash with this error:

    Code:
    Error occurred on line: 115 (Starter)
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.shell.Shell.runGoodChain(
    Shell.java:463)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:285)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:249)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    139)
        at anywheresoftware.b4a.BA$
    2.run(BA.java:360)
        at android.os.Handler.handleCallback(Handler.java:
    739)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    145)
        at android.app.ActivityThread.main(ActivityThread.java:
    6934)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    1404)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1199)
    Caused by: java.lang.ClassCastException: com.company.app.beaconparser$_eddystoneurl cannot be cast 
    to com.company.app.beaconparser$_ibeacon
        at com.company.app.starter._manager_devicefound(starter.java:
    283)
        ... 
    17 more
    Error occurred on line: 
    115 (Starter)
    java.lang.NullPointerException: Attempt 
    to invoke virtual method 'java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])' on a null object reference
        at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:463)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:285)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:249)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    139)
        at anywheresoftware.b4a.BA$
    2.run(BA.java:360)
        at android.os.Handler.handleCallback(Handler.java:
    739)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    145)
        at android.app.ActivityThread.main(ActivityThread.java:
    6934)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    1404)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1199)
    *** 
    Service (httputils2service) Create ***
    ** 
    Service (httputils2service) Start **
    ** 
    Service (httputils2service) Start **
    ** 
    Service (httputils2service) Start **
    ** 
    Service (httputils2service) Start **
    java.lang.RuntimeException: java.io.EOFException
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    170)
        at anywheresoftware.b4a.BA$
    2.run(BA.java:360)
        at android.os.Handler.handleCallback(Handler.java:
    739)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    145)
        at android.app.ActivityThread.main(ActivityThread.java:
    6934)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    1404)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1199)
    Caused by: java.io.EOFException
        at java.io.DataInputStream.readByte(DataInputStream.java:
    77)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:335)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:249)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    139)
        ... 
    9 more
    The app crash because I have Eddystone URL sending at the same time that beacons, when I disable the Eddystone URL app works normally.

    I am using Beacon Toy in google play for simulate Eddystone.

    I was checking with debug mode and crash in this code from Sub ParseEddystone in class Beacon Parser.

    Code:
    Return b(3 - offset) - 41
    Afternoon I have an event and I need both type of beacons, and I can't open app, crash immediately.

    Thanks for your help.
     
    Last edited: Oct 18, 2017
  12. Erel

    Erel Administrator Staff Member Licensed User

    Have you modified the BeaconParser class code?
     
  13. KMatle

    KMatle Expert Licensed User

    Due to lack of BLE tags: How fast are tags recognized when they come in reach?
     
  14. Christian García S.

    Christian García S. Active Member Licensed User

    Thanks @Erel,

    I have not made any changes to the original code.

    Thanks @KMatle

    Beacons and Eddystone are recognized immediately, but APP when Eddystone recognizes the URL crash in the code:

    Code:
    Return b(3 - offset) - 41
    I do not know what you mean about BLE tags.

    Thanks

    Christian
     
    Last edited: Oct 20, 2017
  15. Erel

    Erel Administrator Staff Member Licensed User

    I think that the error message might not be exact here. Please run it in release mode (set #ReleaseLogger: True if using B4A-Bridge) and post the logs.
     
  16. Christian García S.

    Christian García S. Active Member Licensed User

    Hello,

    I want to buy a Bluetooth printer and connecting with bluetooth admin, I can use Beacon parser and still keep connected (paired) with printer??

    I want to know before buy the printer.

    Thanks in advance.

    Christian
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  18. Eduardo Enri

    Eduardo Enri Member Licensed User

    Erel, this example is very interesting, but it would be easy to update it to use the recent xCustomListView instead of the old CustomListView ?.

    Thanks in advance!
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    B4A example updated:
    - Based on xCustomListView.
    - targetSdkVersion set to 26.
    - COARSE permission added and requested at runtime.
     
    Eduardo Enri likes this.
  20. Eduardo Enri

    Eduardo Enri Member Licensed User

    Great!

    Thank you Erel.
     
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