The scenario is:
I have an android dongle running my app and in the other side I have an HM10 LE bluetooth attached to an esp8266.
I'm trying to connect via bluetooth the android dongle through my app to the HM10.
I've done this successfully during weeks, even connecting the android dongle with different HM10 or vice versa, the same HM10 with other dongles.
The problem:
After a certain period, during the connection try, I've started to receive a Disconnected state with status 133, but after some connection retries the connection happened successfully.
Now, I'm not able to connect a specific android dongle (Let's call it problematic dongle) with a specific HM10 (let's call it problematic HM10). I'm always receiving the 133 and even with hundreds of retries it is not able to connect.
But, If I use another dongle, I'm able to connect to "the problematic" HM10. Also, if I use another HM10, I'm able to connect to "the problematic" dongle.
Finally, it also happens that, when I connect another HM10 to the problematic dongle, right after it, I'm able to connect the problematic HM10 to the problematic dongle. But, if I disconnect it, I will never be able to connect again.
When I try to connect to a specific BLE Device I always receive a Disconnected state with status=133.
What I've tried to solve it:
It's important to say that, during a normal usage, the HM10 can be turned of and vice versa. Though, when I grab the disconnect event on the "onConnectionStateChange" in the Gatt Callback I always close the gatt ( deviceGatt.close(); )
I also read in some posts to refresh the deviceGatt before close it, so I'm also doing it:
//inside the onConnectionStateChange on the BluetoothGattCallback:
case BluetoothProfile.STATE_DISCONNECTED:
mConnectionState = ConnectionStatus.DISCONNECTED;
readCharacteristic = null;
writeCharacteristic = null;
if ( status != BluetoothGatt.GATT_SUCCESS ) {
if ( status == 133) {
refreshDeviceCache(deviceGatt);
}
}
deviceGatt.close();
deviceGatt = null;
break;
}
private boolean refreshDeviceCache(BluetoothGatt gatt){
try {
BluetoothGatt localBluetoothGatt = gatt;
Method localMethod = localBluetoothGatt.getClass().getMethod("refresh", new Class[0]);
if (localMethod != null) {
boolean bool = ((Boolean) localMethod.invoke(localBluetoothGatt, new Object[0])).booleanValue();
return bool;
}
}
catch (Exception localException) {
}
return false;
}
I also read in one post to clean the cache in the android settings->Wireless&Networks->More->Network settings reset, but the problem still exists after doing it.
Please find the logs below:
11-27 11:16:49.353 8104-8130/? D/bt_hci_h5: hci_hal_h5 h5_transmit_data, data type: 1
11-27 11:16:49.353 8104-8130/? D/bt_hci_h5: cmd opcode = 0xfc19
11-27 11:16:49.353 8104-8130/? D/bt_hci_h5: hci_hal_h5 h5_int_transmit_data_cb data type: 5
11-27 11:16:49.353 8104-8144/? W/bt_btif: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0008
11-27 11:16:49.353 8104-8144/? W/bt_btif: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0008
11-27 11:16:49.353 8104-8144/? W/bt_btif: bta_gattc_conn_cback() - cif=5 connected=0 conn_id=5 reason=0x0008
11-27 11:16:49.353 8104-8144/? W/bt_btif: bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0008
11-27 11:16:49.353 8104-8144/? W/bt_btif: bta_gattc_conn_cback() - cif=7 connected=0 conn_id=7 reason=0x0008
11-27 11:16:49.353 8104-8144/? E/rtk_parse: rtk_delete_le_profile, hci_conn not exist with handle ffff
11-27 11:16:49.353 8104-8144/? I/bt_btm_sec: btm_sec_disconnected clearing pending flag handle:16 reason:8
11-27 11:16:49.354 8104-8126/? D/BtGatt.GattService: onConnected() - clientIf=7, connId=0, address=34:15:13:E6:50:8F
11-27 11:16:49.354 8104-8130/? D/bt_hci_h5: hci_hal_h5 h5_int_transmit_data_cb data type: 5
11-27 11:16:49.354 24277-24288/? D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=7 device=34:15:13:E6:50:8F
11-27 11:16:49.358 24277-24288/? D/BluetoothComm: Error connecting to device: com.polidea.rxandroidble.exceptions.BleDisconnectedException: Disconnected from 34:15:13:E6:50:8F
11-27 11:16:49.359 24277-24288/? W/System.err: com.polidea.rxandroidble.exceptions.BleDisconnectedException: Disconnected from 34:15:13:E6:50:8F
11-27 11:16:49.359 24277-24288/? W/System.err: at com.polidea.rxandroidble.internal.connection.RxBleGattCallback$2.onConnectionStateChange(RxBleGattCallback.java:76)
11-27 11:16:49.359 24277-24288/? W/System.err: at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:184)
11-27 11:16:49.359 24277-24288/? W/System.err: at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:70)
11-27 11:16:49.359 24277-24288/? W/System.err: at android.os.Binder.execTransact(Binder.java:565)
11-27 11:16:49.362 24277-24324/? D/BluetoothManager: getConnectionState()
11-27 11:16:49.362 24277-24324/? D/BluetoothManager: getConnectedDevices
11-27 11:16:49.367 24277-24324/? D/BluetoothGatt: close()
11-27 11:16:49.367 24277-24324/? D/BluetoothGatt: unregisterApp() - mClientIf=7
11-27 11:16:49.368 8104-8158/? D/BtGatt.GattService: unregisterClient() - clientIf=7
11-27 11:16:49.465 8104-8130/? D/bt_vendor_uart: op for 7
11-27 11:16:49.465 8104-8130/? D/bt_hci_h5: hci_hal_h5 h5_transmit_data, data type: 1
11-27 11:16:49.465 8104-8130/? D/bt_hci_h5: cmd opcode = 0xfc94
Here is a screenshot of the btsnoop_hci.cfa:
//update - adding file log
Here is the log file
//end update
I read a lot of post about this issue but or doesn't have a solution or the solution provided didn't work.
I'm without options so, I wonder If someone could help me on this. Any thoughts?
There is nothing wrong with the Android software. The problem is that the BLE radio link doesn't seem to stay connected. You could use an air sniffer to try to monitor what's going in the air; why the packets are lost. There is of course also a possibility that either of the two Bluetooth controllers' Link Layers misbehave. I would recommend to verify that the hardware really works and is proper.