This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52dk and nrf connect, Autoconnect after bluetooth adapter turned off and on

Hi,

I tried nrf connect and nrf hrs example. I used nrf52DK.
I bonded the device, and connected with autoconnect.
I turned off the nrf 52 DK, and turn on. The nrf connect app on the phone can saw the state when disconnect, and can reconnected after some seconds, so the autoconnect feature worked.
But the autoconnect feature not worked in this scenario:
If when connected together, (phone writes: connected) i turned off the bluetooth adapter (the app wrote bluetooth adapter not turned on, and device state is changed to disconnected), and turned on the bluetooth adapter on my phone (the program not wrote the bluetooth adapter off error), and wait, but the phone not connect automaticaly to nrf 52 DK. If i push the connect button, its working.
So auto connect feature not work properly. If i turn off and on the dev kit, autoconnect works, but if i turn off and on the phones bluetooth adapter, nrf connect not connect automaticaly.
Its an error? Why not work? What can i do to connect automaticaly, after the bluetooth adapter turned off and on?
I want to make an app, which task is reconnect, every scenario, and want to use the autoconnect feature, but its not working as expected.
Can you help?

Thanks,
Janos

  • Hi Janos,

    You have to implement autoconnection after toggling Bluetooth or airplane mode yourself, but it is not complicated. Please refer to this excellent post for details.

  • Thanks the suggestion. But your linked post writes:

    "* We recommend using BLE Library (
    https://github.com/NordicSemiconductor/Android-BLE-Library/)

    as it handles some of those automatically."

    I using this lib, and has a feature, "autoconnection". But its not work properly.

    I don't want implement the feature again manualy and rewrite my app, if the autoconnection has in the lib.

    My suggestion is please forward the ticket to a technical team. Thanks for your help.

    Janos

  • Hi Janos,

    This should be in order if you use the Android-BLE-Library and set autoConnect set to true when you connect, and this is not the first connection. It is not clear to me if/how you have done this. Can you show us the relevant parts of your code?

    Einar

  • I tried with your official apps and tools, and its not work. Please try the nrf connect app, and the nrf hrs example app in sdk. The nrf connect uses Android-BLE-Library.
    My steps:
    1. I bonded the device in nrf connect
    2. I Connected with autoconnect in the nrf connect app.
    3. I turned off the nrf 52 DK, and turn on. The nrf connect app on the phone can saw the state when disconnect, and can reconnected after some seconds, so the autoconnect feature worked.
    4. But if when connected together, (phone writes: connected) i turned off the bluetooth adapter (the app wrote bluetooth adapter not turned on, and device state
    is changed to disconnected), and turned on the bluetooth adapter on my phone (the program not wrote the bluetooth adapter off error), and wait, but the
    phone not connect automaticaly to nrf 52 DK. If i push the connect button, its working.
    5. So auto connect feature not work properly. If i turn off and on the dev kit, autoconnect works, but if i turn off and on the phones bluetooth adapter,
    nrf connect app not reconnect automaticaly.
    So i write relevant parts of my code, but not work the lib autoconnect function in your nrf connect official app too.
    So its trivial, if the lib autoconnect feature not working properly in your official apps, then in my app, not working as expected...

    Thanks,
    Janos

  • Hello,

    This behavior is intended. The 'autoConnect' feature works until you call 'close()' method on the BluetoothGatt object. Turning off Bluetooth on the phone closes all GATT (BluetoothGatt) objects, so the phone forgets which device was connected, which not, etc.

    In order to make it work like you'd like, you have to listen to the Bluetooth ON broadcast and call connectGatt with parameter autoConnect=true again. However, if your device is not bonded and uses a private Bluetooth address, you need to scan for it before connecting, otherwise the phone will expect public address and the connection attempt will fail (system will scan for an adv packet for a device advertising with the same 48-bit address, but with 49th bit set to public). Scanning in your app will ensure that the system saves the address and its type when it's found.

    As I wrote in the other post, if you also want to automatically connect after the phone gets reboot, you need additionally listen to ACTION_BOOT_COMPLETE broadcast.

Related