I want to ask if you can send me your iBeacon extension for APP Inventor, please. Thank you very much in advance.
I think the following way should work with Beacons directly, only with the BLE library. Unfortunately, I can't program such an extension
BLE Scan returns ScanResult, which contains ScanRecord:
public ScanResult (BluetoothDevice device,
int eventType,
int primaryPhy,
int secondaryPhy,
int advertisingSid,
int txPower,
int rssi,
int periodicAdvertisingInterval,
ScanRecord scanRecord,
long timestampNanos)
Raw Beacon data are returned by the getBytes () method from ScanResult.ScanRecord.getBytes ()
The input of the function will be DeviceAdress.
In the test app you can leave blank the parameter "N cicli" as it defaults to 1 (seconds). You can use this parameter just for increasing the interval of time over which the "closest beacon" is evaluated, because the distance of a transmitting beacon is derived from the signal intensity which is not very steady.
I'm sorry but I didn't completed yet a documentation, although the usage i very simple:
a block (StartScansione) allows you to start detecting beacons (so far only iBeacons and AltBeacons, not Eddystone)
an event occurs when a new beacon is detected or when a previously detected beacon disappears: the corresponding "when" block (ListaBeaconsChange) returns the list of all the beacons detected (each element is a beacon and is identified by UUID, Major, Minor and estimated distance)
an event occurs when a detected beacon becomes the closest beacon: the corresponding "when" block (ClosestBeaconChange) returns UUID, Major and Minor of that beacon
You also have a block (StopScansione) for stopping the detection and you can set the following parameters:
NCicli (I explained it before)
ListaUUIDs (for filtering the detection and limiting to some specific UUIDs you can provide as a list item)
DistanzaMinima (for filtering the detection just to beacons whose estimated distance is <= DistanzaMinima // DistanzaMinima defaults to 1000mt)
If you are using an Android version greater then 9 you must MANUALLY grant the location permissions to the test app (and any other app making use of blebeacons extension) OTHERWISE NO BEACON WILL BE DETECTED !
dear Piero_Della_Romanesc,
thank you very much for the extension.
Have you solved the "manifest problem" in any way to be able to develop the application using MIT AI2 companion? I ended up with "Error from Companion: The BeaconService is not properly declared in AndroidManifest.xml. If using Eclipse, please verify that your project.properties has manifestmerger.enabled = true". Sorry, I'm not an Android player and I don't know what to do with this
Great job, the features seem clear and fully usable, I just miss the ability to display RSSI (TX-power). This value is also part of the iBeacon BLE packet and you can read it because you offer a function that filters according to it. Would it be possible to get RSSI in addition to UUID, Major and Minor? Thanks
Dear John,
MIT AI2 companion is very useful for testing an app, but it has some compatibility flaws when using some extensions. Unfortunately, the "BLEbeacons" extension is one of them.
Therefore you will have to generate the .apk file of your app (AndroidManifest.xml in this case will be generated correctly) and install it on a physical Android device with a physical bluetooth interface.
As for the missing fields (rssi etc.) in a future version of the extension they will be added to the content of the "ClosestBeacon" and "ListaBeacons" fields.
Thank you very much, Piero_Della_Romanesc. It already works for me, but the response is too slow. Even a change in "N cicli" will not solve it. My iBeacon broadcasts with a period of 400ms. Can you think of a way to get an "immediate response"?
hi John
the extension uses the altbeacon library which provides the following methods:
-setForegroundScanPeriod
-setForegroundBetweenScanPeriod
-setBackgroundScanPeriod
-setBackgroundBetweenScanPeriod
However the current version of the extension does not allow to modify these parameters which are fixed to:
-setForegroundScanPeriod = 5000ms
-setForegroundBetweenScanPeriod = 0ms
-setBackgroundScanPeriod = 25000ms
-setBackgroundBetweenScanPeriod = 30000ms
If you shorten ScanPeriod too much you risk missing some brodcasts.
I don't know the needs of your application but in a future version of the extension I might add the ability to change the defaults.
Alternatively I could send you the Java code of the extension so that you can create your own version.
Let me know
Buonasera John,
buone notizie !
ho aggiornato l'estensione BleBeacons all'ultima versione (2.19.3) della libreria Altbeacon.
Ho colto l'occasione di aggiungere le modifiche che mi chiedevi:
possibilità di ottenere i valori TxPower e RSSI per i beacon rilevati
possibilità di impostare i valori di
-ForegroundScanPeriod
-ForegroundBetweenScanPeriod
ood evening John,
Good news !
I updated the BleBeacons extension to the latest version (2.19.3) of the Altbeacon library.
I took the opportunity to add the changes you asked me:
possibility to obtain the TxPower and RSSI values for the detected beacons
possibility to set the values of
-ForegroundScanPeriod
-ForegroundBetweenScanPeriod
-BackgroundScanPeriod
-BackgroundBetweenScanPeriod
Dear John,
Actually, the NCicli parameter only affects the frequency of the ClosestBeaconChange event, in the sense that ClosestBeacon is the beacon that has the shortest distance in a period of time equal to NCicli * ForegroundScanPeriod among all the detected beacons.
While ClosestBeaconParm is the beacon that has the shortest distance among all the beacons detected in the ForegroundScanPeriod time period.
If NCicli> 1 the ClosestBeaconChange event will occur less frequently than the ClosestBeaconParmChange event.
Depending on the purpose of your app you will be able to use either of the two events.
First of all, thank you very much for sharing your extension. I was wondering, is there is a way to extract the raw data that the beacon is broadcasting?
Hi Daniela,
the extension is based on the Altbeacon library (Android Beacon Library 2.19.3) of which only some of the available fields are used.
However, it does not seem to me that the aforementioned library provides the data you request.
You can check for yourself the fields and methods available for the "beacon" class on this link: https://altbeacon.github.io/android-beacon-library/javadoc/org/altbeacon/beacon/Beacon.html
Hi DanielaAH,
Were you able to figure out how to extract raw data from the beacon ? I am a newbie and will much appreciate help in form of .aia/.apk/ block diagrams.
Thanks in advance.