alexanderlavrushko / BLEProof-collection

Example of complete BLE application: Central and Peripheral for Android, iOS, ESP32, Arduino Nano 33
124 stars 39 forks source link

BLE keeps getting disconnected #4

Open IvRogoz opened 1 year ago

IvRogoz commented 1 year ago

Im using ESP32-S3 and is working fine. Im able to access it over serial. But in Android app Im getting disconnect errors?

D/appendLog: Bluetooth ON, permissions OK, ready D/appendLog: Starting BLE scan, filter: 25ae1441-05d3-4c5b-8281-93d4e07420cf D/appendLog: status = Scanning D/BluetoothAdapter: isLeEnabled(): ON D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=10 mScannerId=0 D/appendLog: onScanResult name=ESP32 address= 68:B6:B3:3E:0A:75 D/appendLog: Stopping BLE scan D/BluetoothAdapter: isLeEnabled(): ON D/appendLog: status = Connecting D/BluetoothGatt: connect() - device: 68:B6:B3:3E:0A:75, auto: false, eattSupport: false D/BluetoothGatt: registerApp() D/BluetoothGatt: registerApp() - UUID=296afc4f-9c60-430b-9d15-ff6198735d0a D/BluetoothGatt: onClientRegistered() - status=0 clientIf=10 D/appendLog: Already stopped D/appendLog: status = Disconnected D/BluetoothGatt: onClientConnectionState() - status=4 clientIf=10 device=68:B6:B3:3E:0A:75 D/appendLog: ERROR: onConnectionStateChange status=4 deviceAddress=68:B6:B3:3E:0A:75, disconnecting D/BluetoothGatt: close() D/BluetoothGatt: unregisterApp() - mClientIf=10 D/appendLog: status = Disconnected D/appendLog: Already stopped D/appendLog: status = Disconnected

YuunOoO commented 3 months ago

Hello, I've encountered a similar issue with Android on some devices. It turned out that certain devices require a bit of time before we begin searching for characteristics. This part resolved my problem.

Handler(Looper.getMainLooper()).post { lifecycleState = BLELifecycleState.ConnectedDiscovering sleep(100) //fix gatt.discoverServices() }