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

Android do not autoconnect when nrf51822 is set to advertise on connect mode

Device : nrf51822 Softdevice : S110 v7.0.0

Title says it all. Autoconnect is working fine on my Android phones when nrf51822 is always programmed BLE_GAP_ADV_TYPE_ADV_IND. Per Nordic's SDK, this setting means only one mobile device can connect and in a connected state, nrf51822 is not visible to other mobile devices as it stops advertising.

Following SDK, nrf51822 is programmed to start in BLE_GAP_ADV_TYPE_ADV_IND and when it get connected it is re-programmed with BLE_GAP_ADV_TYPE_ADV_NONCONN_IND. Below is the code snippet handling the transitions :

static void on_ble_evt_postprocessing(ble_evt_t * p_ble_evt) {

switch (p_ble_evt->header.evt_id)
{
    case BLE_GAP_EVT_CONNECTED:

advertising_start(BLE_GAP_ADV_TYPE_ADV_NONCONN_IND );  
break;

    case BLE_GAP_EVT_DISCONNECTED:
  advertising_start(BLE_GAP_ADV_TYPE_ADV_IND);
        break;

    default:
        // No implementation needed.
        break;
}

}

Only when I do the above programming, my Android phones' autoconnect do not work. They work smoothly when I just use the BLE_GAP_ADV_TYPE_ADV_IND. Below is the autconnect code used in Android :

	[ConnectGatt](developer.android.com/.../BluetoothDevice.html, boolean, android.bluetooth.BluetoothGattCallback))(Context, true, cbAutoConnect);
	
	

Anyone seeing this issue? Any solution or insights on this would be super helpful.

Parents
  • Hi TechGeek,

    I did a test here with a SamsungS6 Android 6.0.1 but I don't see that problem. I setup a device doing what you described, advertising in non-connectable mode when in connection and switch back to connectable mode when disconnected. When connecting with Autoconnect selected on nRFConnect app, it can connect after I reset the device to go back to connectable mode. The phone simply wait until timeout happens and then connect again.

    I would suggest you to make sure you advertise in connectable mode after it get disconnected not in non-connectable. Also try to test on other phone.

  • Re: "Suggest you to make sure you advertise in connectable mode after it get disconnected not in non-connectible". This is taken care of by the below code snippet I shared earlier:

    case BLE_GAP_EVT_DISCONNECTED: advertising_start(BLE_GAP_ADV_TYPE_ADV_IND); break;

    Let me know if this is not the case or you are recommending something different than the above.

    Re: Test on other phone. I tested on 2 phones : Samsung Galaxy S7 and OnePlus One. Both same result.

Reply
  • Re: "Suggest you to make sure you advertise in connectable mode after it get disconnected not in non-connectible". This is taken care of by the below code snippet I shared earlier:

    case BLE_GAP_EVT_DISCONNECTED: advertising_start(BLE_GAP_ADV_TYPE_ADV_IND); break;

    Let me know if this is not the case or you are recommending something different than the above.

    Re: Test on other phone. I tested on 2 phones : Samsung Galaxy S7 and OnePlus One. Both same result.

Children
No Data
Related