Android altbeacon Library - How to access complete payload of scanned Beacon - android

How can I access the raw payload data of a Scanned Beacon using the altbeacon library?

The Android Beacon Library is not designed for this purpose, so the APIs to do what you want are a little awkward.
Upon detection the library automatically parses payload and converts the bytes to a beacon object. But because the library also supports transmission it has utilities to convert a beacon object right back to bytes. If using iBeacon, you can convert a detected beacon back to raw bytes like this:
BeaconParser iBeaconParser = new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
byte[] payloadBytes = iBeaconParser.getBeaconAdvertisementData(beacon);
In general, this is a lossless process, as beacon formats typically use up every byte of the payload. In the unlikely event that you have a custom beacon format that does not use all the bytes, you would need to alter the format slightly to add extra data fields at the end so that the full payload is parsed into the beacon. Otherwise you will lose these extra bytes in the conversion.

Related

Capturing data packets from beacon using Altbeacon

I've a specific beacon that transmits data packets. I can see that Altbeacon library recognises this beacon (from minorId) and I can see that packetCount is 1, but what I cannot see is packet itself (from Beacon object). How can I do that? How can I get Beacon advertisement bytes - I know I can use setDebug(true) to see them in console, but is it possible to retrieve it in code programatically? How? Thanks in advance.
Beacon sends three things which you can capture using functions like beacon.getId1() which is UUID, beacon.getId2() which is major and getId3() which is minor.

BLE Beacon with custom data broadcasting

In the application I am looking forward Bluetooth in Beacon is very good option as I want to collect PH from different sources to the application so I can't pair my android device with all the BLE devices at a time as it will be around 20-30.
But I can see that if there is Beacon then Android can scan all of them and also get the RSSI of all devices without being paired with them.
So is it possible that we add few other parameter for example PH, Temperature, Humidity and 3-4 other parameters so Beacon is going to broadcast all these parameter along with RSSI and in Android app I can collect all the information?
I am not sure if this is feasible solution or not and if it is then how to achieve this in beacon?
Bluetooth beacons generally rely upon advertisement packets to send data, which are limited in the number of bytes available. For manufacturer advertisements, you basically have 24 usable bytes to work with, although you need to reserve some of these as a flag to indicate it is your beacon format, and not somebody else's beacon format.
You can look at the AltBeacon spec as an example. This format uses two bytes to identify itself (the "beacon code"), 20 bytes of beacon identifiers, one byte of data and one byte for reference RSSI. You probably still want a unique identifier for each beacon so you know which beacon sent you the information. But you might be able to cut this down to four bytes for your purposes, which would allow you to have 2^32 different beacons sending this information.
The Android Beacon Library lets you both transmit and receive beacons using arbitrary formats you can define using the BeaconParser class. A beacon format that uses a four byte identifier, two bytes each for PH, Temperature and Humidity data fields, and two bytes each for five other data fields might look like this:
m:2-3=abcd,i:4-7,d:8-9,d:10-11,d:12-13,d:14-15,d:16-17,d:18-19,d:20-21,d:22-23,p:24-24

Can i get more than 2 bytes from iBeacon using AltBeacon lib?

The question is, how i can get the manufecturer data that is Int type. Device send me a packet like - https://support.kontakt.io/hc/en-gb/articles/201492492-iBeacon-advertising-packet-structure, so as i understand there are 4 bytes for manufecturer data, but the lib could parse only 2 bytes value - 0xFF
Using altbeacon library on Android.
Based on the format listed in the linked document, you can access the first two bytes of what it calls "manufacturer data" with:
beacon.getManufacturer()
and the second two bytes with
beacon.getBeaconTypeCode()
Strictly speaking, all of the bytes of the beacon advertisement are manufacturer data, so the referenced document referring to only four bytes as "manufacturer data" is a bit misleading. The method names above divide these four bytes into the two fields above because this is their standard usage when working with bluetooth beacons.

Encrypting Altbeacons

I am attempting to create UUID's that incorporate security measures that prevent replay attacks. I plan to attach a timestamp to the UUID and Encrypt the beacon. The encryption creates a 16 byte object but The Beacon Transmitter requires the UUID to be a string of consistent length. Is there a way I can transmit a Byte object instead of string. Also, I need the encrypted beacon to change with the time. Should I do a:
beaconTransmitter.startAdvertising(beacon);
timeout(1 second);
beaconTransmitter.stopAdvertising(beacon);
and recursively call my beacontransmit method?
If your encryption really makes a 16 byte object, then you should be able to convert it to a UUID, which is also 16 bytes long. It should be as simple as:
Identifier uuid = Identifier.fromBytes(byteArrayOfLength16, 0, 15, false);
However, encryption algorithms typically make a much longer byte array as the output. You could remove all but 16 of the bytes from the encrypted output to make a hash (this is basically what Eddystone-EID does), but this won't be able to be decrypted. The receiving device would have to perform the same encryption calculation for a given timestamp to see if it calculates the same value. If it does, it knows it has found a match.
Yes, the approach of starting advertising based on one timestamp, waiting for a delay, and starting advertising based on a new timestamp is certainly the way to go.

How much amount of arbitrary data can be included in Beacon PDU?

We're trying to emulate a beacon on a Android device and would like to include some 50 bytes of application data in payload? We found that with AltBeacon format this is not possible? How can it be done with help of AltBeacon lib for Android?
Moreover, what are primary and secondary beacon advertisements?
What is role of GattBeacon in this context and when and how should it be used?
There are two basic types of BLE beacon advertisements:
Manufacturer advertisements (iBeacon, AltBeacon, Gimbal)
GATT Service Advertisements (Eddystone, UriBeacon, GattBeacon)
They differ mainly by the bluetoorh PDU type, but in both cases the number of bytes that can be transmitted are similarly limited. It is 23 bytes for manufacturer advertisements (not counting the two byte manufacturer code).
With Bluetooth 4.x, you just won't get close to 50 bytes in a single packet. Bluetooth 5.0 is expected to increase this at some point in the future.
None of the beacon layouts let you go beyond this limit. GattBeacon is merely a generic example layout of a beacon based on GATT Service advertisements, and is not meant for practical use.

Categories

Resources