I am using Nexus 4(4.4 kitkat) as central and iPad as peripheral.Peripheral has a service which it is advertising.The advertising packet has some data(22bytes) + service UUID.When I try to scan for the peripheral from Android, iPad peripheral is discovered.However when I try to get the service UUID from scanRecord parameter in the callback, I could not find it.All I get is the 20byte data which the peripheral is sending.When I try to scan for devices with the UUID I am not able to discover those peripherals.
Following is the iOS code to advertise a service.The service id being used is "0000192f-0000-1000-8000-00805f9b34fb"
CBUUID *serviceUuid = [CBUUID UUIDWithString:TRANSFER_SERVICE_UUID];
[self.peripheralManager startAdvertising:@{CBAdvertisementDataServiceUUIDsKey : @[serviceUuid],
CBAdvertisementDataLocalNameKey:[[BTLEConfigs sharedBTLEConfig] getAdvertizingUUID]}];
The device gets discovered when I scan without service UUID.
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi, final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//-- how to retrieve the service id from scanRecord
}
});
}
};
The services are discovered between two iOS devices but between Android device and iOS peripheral its not working.How to scan a peripheral with 16bit service UUID?Any help is appreciated.
The scan record byte array contains EIR formatted data. See the Bluetooth Core Specification section 8.
The scan record contains one or more sequential EIR entries, which have the following format:
<entry length (1 byte)> <data type (1 byte)> <data (length - 1 bytes)>
You are looking for an EIR entry with a type of 0x02 or 0x03 (see Bluetooth Core Specification section 18.2). The data for the entry will contain one or more UUIDs in Little Endian format.
Example scan record:
02011a0303b4540a094c69676874426c7565
Can be broken down into:
02 01 1a Flags - 1a
03 03 b454 16-bit service UUID - 54b4
0a 09 4c69676874426c7565 Local name - LightBlue
This is a known bug in Android BLE -the filtering only works with 16bit UUID not full 128bit.
See Google issue 58931
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With