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,

    Are you testing with iOS or Android phones? Generally you can connect automatically in the background if you are using your custom app. If not, then the OS will typically only automatically connect to devices that include a few specific services, such as for instance HID keyboard. This all depend on the phone, though. As long as the nRF peripheral advertises, then it is up to the phone to connect.

    Br,

    Einar

  • Hi Einar,

    I testing with android phones (Xiaomi Mi A1, and Google Pixel 2), and not works both.
    The Nordic android ble lib has feature autoconnect=true. In the lib code, i see, the device can autoconnect in the background, when i use autoconnect=true when i call connect(). It has a broadcastReceiver, which listen to bluetooth state, and manage it, so i think it can reconnect automaticaly, when i turned off bluetooth, and turned on again. The autoconnect works, when device out of range, but if modify the bluetooth state, the autoconnect not work. So i think the lib has a bug, or the lib has not contains this feature? I need to reconnect manualy in the background if the bluetooth adapter turning off and on? If its true, the autoconnect=true whats doing generaly? If i bond the phone with the device, the autoconnection feature works better, or not? The autoconnection depends bonding, or not?
    How can i get more information about my phones connection handling mechanics?
    Can you give me more information about autoconnection, and the nordic lib autoconnection feature?

    Thanks,
    Janos

  • Hi Janos,

    Kovacs.janos256 said:
    The autoconnection depends bonding, or not?

    You have to use bonding in this case. If you don't use bonding, then this is expected behavior. The android phone will typically flush all Bluetooth related information when you toggle airplane mode, and then it will not have any information about which to reconnect to. So the proper way to fix this is to use bonding.

    Kovacs.janos256 said:
    How can i get more information about my phones connection handling mechanics?

    It might be better to ask in a Android forum for Android specific questions, or contact the phone manufacturer for very specific questions related to specific devices. (This does not seem relevant here though, if the problem is just that you are not using bonding.).

    Kovacs.janos256 said:
    Can you give me more information about autoconnection, and the nordic lib autoconnection feature?

    There is not much more to say. It will auto connect, but not to non-bonded devices when you toggle airplane mode. I do not believe that is possible. You could however expand your app to scan in the background and connect to the device. Then it would not really be automatically, but you could probably implement this in your app so that it seems automatic for the user.

    Br,

    Einar

  • Hi Einar,

    I using bonding, and the autoconnect feature not work with bluetooth off and on, and airplane mode. And the nrf hrs example using bonding too, but not working as expected, not reconnect automaticaly if i toggle airplane mode or bluetooth. But i bonded the nrf52dk with the phone, and not working. I tried my custom app, but i tried with nrf connect app too, and not working. Whats the problem? I using bonding. I connect with autoconnect=true. Why not reconnect after toggling bluetooth or airplane mode? Can you give a try with an nrf 52 dk and your phone, with nrf connect app? Try to bond, and connect with autoconnect. If you take the device out of range, the phone can connect after found the nrf52 dk, but if you toggle bluetooth or airplane mode, the phone not connect back automaticaly, you need to push to connect button. I think this is a bug in the nrf ble lib. You sayd the lib support this feature, and i see the broadcastReceiver in the lib, which can tell the lib if the bluetooth state changes. So if the lib supports this feature, and i use bonding, and connect with autoconnect=true, why not work?

    Thanks,
    Janos

Related