In the past 6 months, I am working on the BLE applications. In my recent project, I am integrating a custom BLE device, and it's making a synchronization issue while reading data. The "onCharacteristicRead" always return 133 error code. Please go through the complete scenario and if anyone has any solution please help me.
Scenario The custom BLE device has three services available.
Emergency
Catch All
Battery Level
I required only two services in my application. Battery and Emergency. Initially, I will scan the device using the below code,
private void scan() {
if (isLollyPopOrAbove()) {// Start Scanning For Lollipop devices
mBluetoothAdapter.getBluetoothLeScanner().startScan(scanFilters(), scanSettings(), scanCallback); // Start BLE device Scanning in a separate thread
} else {
mBluetoothAdapter.startLeScan(mLeScanCallback); // Start Scanning for Below Lollipop device
}
}
private List<ScanFilter> scanFilters() {
String emergencyUDID = "3C02E2A5-BB87-4BE0-ADA5-526EF4C14AAA";
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(emergencyUDID)).build();
List<ScanFilter> list = new ArrayList<ScanFilter>(1);
list.add(filter);
return list;
}
private ScanSettings scanSettings() {
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_BALANCED).build();
return settings;
}
This is working fine and I am getting the scan result and I can connect to the device. Once the connection establish, I will make the below call from GattCallBack
mBluetoothGatt.discoverServices();
Then I am getting the service discovery completed callback
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) { //BLE service discovery complete
if (status == BluetoothGatt.GATT_SUCCESS) { //See if the service discovery was successful
Log.i(TAG, "**ACTION_SERVICE_DISCOVERED**" + status);
broadcastUpdate(BLEConstants.ACTION_GATT_SERVICES_DISCOVERED); //Go broadcast an intent to say we have discovered services
} else { //Service discovery failed so log a warning
Log.i(TAG, "onServicesDiscovered received: " + status);
}
}
From here I find the Available MLDP services using the provided UUID's. This is also working fine.
But when I read characteristics,
public void readCharacteristic(BluetoothGattCharacteristic characteristic) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) { //Check that we have access to a Bluetooth radio
return;
}
boolean status = mBluetoothGatt.readCharacteristic(characteristic); //Request the BluetoothGatt to Read the characteristic
Log.i(TAG, "READ STATUS " + status);
}
The response status is getting true but "onCharacteristicRead" callback always getting as 133
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { //A request to Read has completed
//String value = characteristic.getStringValue(0);
//int value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, 0);
// if(characteristic.getUuid().e)
if (status == BluetoothGatt.GATT_SUCCESS) {
//See if the read was successful
Log.i(TAG, "**ACTION_DATA_READ**" + characteristic);
broadcastUpdate(BLEConstants.ACTION_DATA_AVAILABLE, characteristic); //Go broadcast an intent with the characteristic data
} else {
Log.i(TAG, "ACTION_DATA_READ: Error" + status);
}
}