troystribling / BlueCap

iOS Bluetooth LE framework
MIT License
714 stars 114 forks source link

Getting disconnected every 33 secs from iOS Central #93

Closed michael-martinez closed 3 years ago

michael-martinez commented 3 years ago

I tried using almost the same code as the Central iOS example project. The other device is an embedded Android device acting as a Peripheral (using native Android BLE APIs).

I am seing disconnection on both sides every 33-34 seconds quite precisely. failure disconnected.

The Peripheral reacts by putting itself back in Advertising mode which is the correct behaviour. For now I handled this by recreating my BLE util class as even using disconnect / reconnect / force disconnect did not work. But this takes almost 5 seconds to reconnect I would like to know the rootcause.

On the Android Peripheral side, configuration is as follows:

private fun startAdvertising() {
        val settings = AdvertiseSettings.Builder()
                .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
                .setConnectable(true)
                .setTimeout(0)
                .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
                .build()

        val data = AdvertiseData.Builder()
                .setIncludeDeviceName(true)
                .setIncludeTxPowerLevel(false)
                .addServiceUuid(ParcelUuid(settingsService.uuid))
                .build()

        advertiser
                .startAdvertising(settings, data, mAdvertiseCallback)
    }

On the iOS Central side, configuration is as follows: readFuture = self.dataCharWifi?.read(timeout: TimeInterval.infinity)

Read operation is performed every 5 seconds by using a timer when the connection / discovery phases are complete. Here is the used iOS Central config if needed: https://gist.github.com/michael-martinez/9f129a8bd45193c647b4692f555d13ca