I trying to create an application ables to read data from a beacon without "connecting" to it. It works well for eddystone beacon, i can read the data thanks to the function "ScanAdvertisement" and "AdvertisementData".
But when i try to read from an iBeacon (knowing the deviceAdress and the serviceUuid thanks to nRF Connect), an error occurs, nothing is read.
Have someone already worked on it ?
Thanks in advance
I developed an extension making use of the Java library "AltBeacon". This extension can detect beacons of type iBeacon and AltBeacon (not Eddystone).
You must consider that those kinds of beacons do not broadcast any data except 4 hex values (UUID, Major, Minor and Tx-Power) which are useful ONLY for indentifying the beacon and evaluating (roughly) its distance from the receiving device.
The extension requires to manipulate the .apk (with apktool) in order
to add some lines in the AndroidManifest.xml.
You are right Taifun, but I'm currently using Kodular where is not yet allowed the "UsesServices" annotation. Meanwhile I could share the Java code of my extension together with the "service" lines to be added in AndroidManifest.xml
Dear @Piero_Della_Romanesc
I am also working on iBeacon using MIT app inventor and I realized that BLE Extension can't help me.
Can you share your extension with me, I would like to try it. Thanks.
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