Reputation: 781
I am using RxAndroidBle Library for my BLE application.
Like nrfConnect application I want to read RAW data from BLE device.
How to read RAW data from device?
Upvotes: 3
Views: 8870
Reputation: 4283
The raw data you see are the hexadecimal values advertised by your bluetooth device.
Your app can read these data using android.bluetooth.le.BluetoothLeScanner
's method:
public void startScan(List<ScanFilter> filters, ScanSettings settings,
final ScanCallback callback);
Here is a sample code of a ScanCallback
implementation you can pass as parameter to read the advertisement data:
ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
BluetoothDevice device = result.getDevice();
byte[] scanRecord = result.getScanRecord().getBytes();
int rssi = result.getRssi();
// Search through raw data for the type identifier 0xFF, decode
// the following bytes over the encoded packet length ...
// yourCallback.onScanResult(device, scanRecord, rssi);
}
};
In your case, the raw data only includes type 0xFF, which is the Manufacturer Specific Data type, on a length of 30 bytes. Your callback handling should search through raw data for the type identifier 0xFF, and decode the following bytes over the encoded packet length.
The types of data included in advertising data varies depending on the device manufacturer, but it should includes at least the Manufacturer Specific Data, which starts with two bytes for the company identifier.
There are other types of BLE advertising data, such as:
This page lists various types of BLE advertising data:
https://www.novelbits.io/bluetooth-low-energy-advertisements-part-1/
Upvotes: 3
Reputation: 3222
To access raw bytes of the advertisement data using RxAndroidBle
you need to:
ScanResult
(RxBleClient#scanBleDevices(ScanSettings, ScanFilter...)
)ScanRecord
(ScanResult#getScanRecord
)byte[]
(ScanRecord#getBytes
)Upvotes: 1