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

luke2012

Well-Known Member
Licensed User
Longtime User
I'm not familiar with this devices but I did a test:

- Tested device name: "Skybeacon"

- Tested with 2 Android phones:
On the left of the attached pic: "Nexus 4" with BLE Scanner App (light blue)
On the right of the attached pic: "Motorola Moto G (2° gen) with the B4A BeaconParser

Result (see attached pic):
BLE Scanner find the beacon in few seconds and keep the beacon info on the screen.
B4A BeaconParser display the beacon info later than BLE scanner and keep the info only for few seconds: after this short interval the beacon info disappears (blank screen).

Note: I'm trying to understand if it only a display bug or a manager bug...

P.S.
thanks in advance for any help or reply
 

Attachments

  • IMG_20161020_091623.jpg
    110.7 KB · Views: 338
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @freedom2000 .
Your App (iTag Alarm) have the same behaviour of BeaconParser. The Skybeacon is displayed (only one time) for few seconds and than disappear (empty screen).
Note that the Skybeacon is near the phone (<1mt).

So it seem that the only app the constantly keep the skybeacon info on the screen is BLE Scanner:

https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner&hl=it

But my target is to implement an app that (always) keep the beacon (skybeacon) info on the screen.
To be onest, actually I don't known why BeaconParser doesn't keep the beacon (Skybeacon) info on the screen. Is related to my beacon settings ? My beacon hardware ? Or others things ?

P.S.
@Erel says: "The second parameter (AllowDuplicates) means that it will "find" the same devices again and again."

My doubt is that this parameter isn't set to AllowDuplicates by default within the attached demo (I have to verify).
 
Last edited:

freedom2000

Well-Known Member
Licensed User
Longtime User

I do believe that allow duplicate is set to true in my app...

Another very good App is nRFConnect. It's a little complex but extremely powerful to help you discover the bowels of our device !
 

luke2012

Well-Known Member
Licensed User
Longtime User
I do believe that allow duplicate is set to true in my app...

Another very good App is nRFConnect. It's a little complex but extremely powerful to help you discover the bowels of our device !

If allow duplicate is set to true, the beacon parser should keep the beacon info on the screen ?
 

luke2012

Well-Known Member
Licensed User
Longtime User
How to monitor the distance dinamically ?
I'm monitoring the distance within the SetDistance Sub (called by StateChanged Sub when the Timer1_Tick is raised) but the distance that I can see is always the same (beacon.distance) also when the device / beacon is moving away.

B4X:
Private Sub SetDistance(lbl As Label, beacon As Beacon)
    lbl.Text = $"Distance: $1.1{beacon.distance} meters"$
    ToastMessageShow($"Distance: $1.1{beacon.distance} meters"$, True)
End Sub
 

luke2012

Well-Known Member
Licensed User
Longtime User
This is the known distance. It will be difficult to see accurate results.
Thanks for your reply Erel. I known that it's difficult to see accurare results.

If is possible, I wish to known:

1) Is it correct that the known distance doesn't change (the known distance is always the same of the first detected distance) also if I move the device away ? In this case the known distance should grow.

2) Is there a possibility to improve the detected distance accuracy? For example improving the code / class or improving the beacon hw / sw side ?

3) My target is to track (in real time and with a good accuracy) the distance between two devices (a Smartphone and a smaller hw device). Is Beacon the right solution for this target ?

4) If the answer to the question 3 is "yes", there are beacons that provide more accuracy and more reliability compared to the beacon that I'm testing: "skybeacon" Shenzhen Sky Electronics Manufactory (model number 20150427)

Thanks in advance for your reply.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the code that calculates the distance:
B4X:
'based on this answer: http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing
Private Sub CalculateDistance(tx As Int, rssi As Double) As Double
   If rssi = 0 Then Return -1
   Dim ratio As Double = rssi / tx
   If ratio < 1 Then
     Return Power(ratio, 10)
   Else
     Return 0.89976 * Power(ratio, 7.7095) + 0.111
   End If
End Sub
The distance should change when the rssi change.
You can improve it by calibrating the three constants.

http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing
 

luke2012

Well-Known Member
Licensed User
Longtime User

Thanks for your suggestion Erel! Very useful for me.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Starting from this sample (Class) I need to monitor the distance also if the App isn't in foreground.
Which is the simpler solution to implement this ?

Thanks in advance for your reply.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Add another Service to the project and call Service.StartForeground. You will also need to acquire a partial lock with PhoneWakeState.

Please start a new thread for further discussion.

Thanks Erel. So I have to move all the Beacon related code from the Starter service to the new (Foregroud) service ?
 

luke2012

Well-Known Member
Licensed User
Longtime User
Only devices with Android 4.3+ and Bluetooth 4.0 works with this BLE Manager object right?

If this is true, is there a way to exclude the devices that doesn't have the above requirements directly on the Play Store putting a manifest code?

Thanks in advance for any help.
 

dataware

Member
Licensed User
hi, am trying to make some another functions on the example, but, when i put a condition, the program is run really slowly, i dont know if is the "If" condition on the SetDistance function what i put it, cause i must identify some especific beacon and his especific range, like this example:

B4X:
Private Sub SetDistance(lbl As Label, beacon As Beacon)
    lbl.Text = $"Distance: $1.1{beacon.distance} meters"$
    If beacon.Distance < 0.05 Then
        If beacon.uniqueid.CompareTo("Some Id")==0 True Then
            ToastMessageShow("Blue", False)
        Else
            If beacon.uniqueid.CompareTo("Some Other Id")==0 True Then
                 ToastMessageShow("Red", False)
            End If
        End If
    End If
End Sub

i hope someone can help me with an optimization, thanks.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…