3

I am using RxAndroidBle Library for my BLE application. Like nrfConnect application I want to read RAW data from BLE device.enter image description here

How to read RAW data from device?

Pallavi Tapkir
  • 781
  • 7
  • 28
  • What do you mean by read RAW data ? Raw data is an array of hexadecimal values read from your device characteristic, or advertisement data, which starts with the vendor ID on 2 bytes, followed with the manufacturer data. – matdev May 20 '21 at 13:25
  • So you mean, manufacturer data from scan record is called as RAW data? I am getting manufacturer data array. I thought both are different. – Pallavi Tapkir May 20 '21 at 14:42
  • 1
    If you want the full raw data of the whole record, use the `getBytes` method, as documented here: https://javadoc.io/static/com.polidea.rxandroidble/rxandroidble/1.7.1/com/polidea/rxandroidble/scan/ScanRecord.html#getBytes--. – Emil May 20 '21 at 15:07
  • raw data includes everything advertised, but in your case, only the manufacturer data are available, type 0xFF. Please check out my answer for other types of advertised data – matdev May 20 '21 at 16:03

2 Answers2

3

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:

  • Service UUID: used to include a list of Service UUIDs
  • Local Name: the device name (either Shortened or Complete)
  • Flags: one-bit flags that are included when an advertising packet is connectable.
  • Advertising Interval: self-explanatory.

This page lists various types of BLE advertising data:

https://www.novelbits.io/bluetooth-low-energy-advertisements-part-1/

matdev
  • 4,115
  • 6
  • 35
  • 56
1

To access raw bytes of the advertisement data using RxAndroidBle you need to:

  1. Perform a scan to obtain ScanResult (RxBleClient#scanBleDevices(ScanSettings, ScanFilter...))
  2. From a result you need to get the ScanRecord (ScanResult#getScanRecord)
  3. From the record you can access raw byte[] (ScanRecord#getBytes)
Dariusz Seweryn
  • 3,212
  • 2
  • 14
  • 21