Failure to connect when using the nRF Connect mobile app for iPhone.

Howdy,

I am using an nRF52840 to perform BLE communication. For this communication I am using extended advertising to perform most of my data transmission. Thing is though, sometimes I need to connect to the device to perform updates and send commands. I set up all the connection callbacks and have the system reestablish advertising after disconnecting. To test all of this, I decided to use the nRF Connect app to test the connection. The problem I am facing is that when I try to connect, it seems to get stuck in a loop of connecting and disconnecting. My phone simply says that it is trying to connect, while my code shows that it is connecting and disconnecting rapidly. I have attached the setup functions and my callbacks for the connection in the code below. Any help would be much appreciated.

static struct bt_conn *default_conn;
struct bt_le_ext_adv *adv;
static struct bt_le_adv_param adv_param = {
	.options = BT_LE_ADV_OPT_USE_IDENTITY | BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_EXT_ADV,
	// .interval_min = BT_GAP_ADV_FAST_INT_MIN_1, // Every 1 to 3 seconds
	// .interval_max = BT_GAP_ADV_FAST_INT_MAX_1,
	.interval_min = BT_GAP_ADV_SLOW_INT_MIN,
    .interval_max = BT_GAP_ADV_SLOW_INT_MAX,
	.peer = NULL
};
struct bt_data adv_data[] = {
	BT_DATA(BT_DATA_MANUFACTURER_DATA, "Random Junk", 12),
};

static void app_led_cb(void)
{
	byte_status = byte_status | 0b00000001; // Set LED status bit to 1
	nrf_gpio_pin_set(LED_R);
	k_timer_start(&led_timeout, LED_TIMEOUT_SECONDS, LED_TIMEOUT_SECONDS);
}

static struct my_lbs_cb app_callbacks = {
	.led_cb    = app_led_cb,
};
static void connected(struct bt_conn *conn, uint8_t err)
{
	if (err) {
        #if INCLUDE_PRINT_STATEMENTS
                printk("Connection failed (error 0x%02x)\n", err);
        #endif
    } 
    else 
    {
        #if INCLUDE_PRINT_STATEMENTS
                printk("Connected\n");
        #endif
    }

	default_conn = bt_conn_ref(conn);
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	printk("Disconnection started\n");
	bt_conn_unref(default_conn);
	default_conn = NULL;
}

static void recycled_cb(void){
	int ret = bt_le_ext_adv_start(adv, NULL);
	if (ret) 
	{
		#if INCLUDE_PRINT_STATEMENTS
				printk("Advertising failed to start (err %d)\n", ret);
		#endif
	}
	printk("Successfully Disconnected\n");
}

static struct bt_conn_cb conn_callbacks = {
    .connected = connected,
    .disconnected = disconnected,
	.recycled = recycled_cb,
};

  • Thank you for the sniffer trace. That was weird. I see that there are a lot of connection request packets, but I can't really tell why it doesn't enter the connection. The reply from the nRF looks identical when the connection is actually happening and not.

    Is it possible to share the application running on the nRF that you used in that sniffer trace, so that I can try to reproduce it locally?

    Best regards,

    Edvin

  • Due to the code having proprietary code I sadly can't share it. I do believe I have identified the problem though. I was reading on the Apple developer forums that there is a known issue with how IOS handles BLE. Apparently, it performs a weird buffer connection that is just a hit or miss on whether it connects. This problem is only really seen when performing extended advertising. I verified this by running my device with regular advertising and it took roughly a second or two to connect. 

    Hope you have an amazing day.

  • No problem. I understand. Thank you for the insight of your findings. The most important part is that you found the cause of the behavior that you were seeing, and that you found a workaround that was working for your case! 

    Best regards,

    Edvin

Related