Reconnect to bonded Smartphone

Hi, 

nRF5340 and SDK v3.0.0 I'm using.

Currently my nRF5340 based BLE device can be bonded with smartphone via passkey, after bond is done, the device stops advertising and be invisible.

From smartphone side:  in case the smartphone is out of range or the bluetooth on smartphone is disabled

From BLE device side: or in case the bond information on the nRF5340 is removed.

Except rebooting the device, there is no way to make them connect to each other again. 

this is the BLE related funcitons:

	if (bt_conn_auth_cb_register(&conn_auth_callbacks)) {
		LOG_ERR("Failed to register authorization callbacks.\n");}

	if (bt_conn_auth_info_cb_register(&conn_auth_info_callbacks)) {
		LOG_ERR("Failed to register authorization info callbacks.\n");}

	bt_conn_cb_register(&connection_callbacks);

	if (bt_enable(NULL)) {
		LOG_ERR("Bluetooth init failed. \n");}

	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();}

	if (bt_services_init(&app_callbacks)) {
		LOG_ERR("Failed to init LBS. \n");}

	LOG_INF("Bluetooth initialized\n");

	if (bt_le_adv_start(BT_LE_ADV_CONN_FAST_2, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd))) {
		LOG_ERR("Advertising failed to start. \n");}

this is BLE related configurations:

# Button and LED library
CONFIG_BT_LBS=y
CONFIG_BT_LBS_POLL_BUTTON=y
CONFIG_DK_LIBRARY=y
CONFIG_BT_LBS_SECURITY_ENABLED=y

# Bluetooth LE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="TEST_BLE"
CONFIG_BT_SMP=y
CONFIG_SETTINGS=y
CONFIG_BT_SETTINGS=y
#data length and MTU
CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
CONFIG_BT_BUF_ACL_RX_SIZE=1024
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_AUTO_PHY_UPDATE=n

**********************************************************************

What I want:

1. just like the earphone, if the connection is lost, they shall be able to reconnect to each other by themselves automatically.

2. if the bond info is removed on the device, it shall advertise and be visible again. 

How can I achive these? 

Regards

Danny

Parents
  • Hello,

    I am terribly sorry for the late reply. We are a bit low staffed, and we are working on holding the queue down. I am sorry for the inconvenience.

    Except rebooting the device, there is no way to make them connect to each other again.

    Do you mean rebooting, or re-programming the device?

    Is it possible to upload the entire application? Mot relevant is the file with all of your Bluetooth implementation, where you set what sort of advertising to use when there is a bonded device, but in case I need to look at something else. That saves us one day of back and forth in case I need some other file.

    Are you able to see this behavior on a DK, or does it require a custom board?

    General: How do you want your peripheral device to behave? If it is connected and bonded to a central device, and then the central disconnects (possibly out of range for a short while). What do you want the peripheral to do? Only accept connections from the already bonded device?

    When do you want it to start accepting new connections? On a button press? After a given amount of time?

    Best regards,

    Edvin

  • Hi  

    fully understandable, it's sommer, the most are in holiday:)

    Anyway thanks a lot for the reply!

    1. rebooting, I mean cycle the power, USB plug out, then plug in.

    2. I don't think it's hardware related.

    3. "General: How do you want your peripheral device to behave?"
    good question: first, they are connected to each other, then the central(smartphone) is out of range, for a certain time, for instance 15 minutes, the peripheral and central shall try to reconnect to each other, after 15 minutes, stop the try.

    yes, only accept connections from the alreay bonded device, as the earphone to smartphone.

    "When do you want it to start accepting new connections? On a button press? After a given amount of time?"

    No buttons on device, if it receives a int signal from the inertial sensor on board occasionally, it will try to start accepting new conncections again, or every 5 minutes there will be a try for reconncetion.

    it's difficult to share the whole project code, just give me some hints, which functions or logic or documents shall I try, I can try it by myself.

    Best regards

    Danny

  • danny0007 said:
    if a interrupt is triggered, then advertise with a whitelist again.

    What sort of interrupt?

    From the declaration of bt_le_adv_param in bluetooth.h:

    	/**
    	 * @brief Directed advertising to peer
    	 *
    	 * When this parameter is set the advertiser will send directed
    	 * advertising to the remote device.
    	 *
    	 * The advertising type will either be high duty cycle, or low duty
    	 * cycle if the BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY option is enabled.
    	 * When using @ref BT_LE_ADV_OPT_EXT_ADV then only low duty cycle is
    	 * allowed.
    	 *
    	 * In case of connectable high duty cycle if the connection could not
    	 * be established within the timeout the connected() callback will be
    	 * called with the status set to @ref BT_HCI_ERR_ADV_TIMEOUT.
    	 */
    	const bt_addr_le_t *peer;

    From hci_types.h:

    #define BT_HCI_ERR_ADV_TIMEOUT 0x3c

    and 0x3c = 60, so the advertising is timing out. I don't see any timestamps in your log. How quickly are you seeing this timeout? 

    When you are doing directed advertising (when your adv_param.peer is set), try replacing BT_LE_ADV_OPT_CONN with (BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY) and use these advertising intervals:

    BT_GAP_ADV_FAST_INT_MIN_2

    BT_GAP_ADV_FAST_INT_MAX_2 (which you already are).

    Best regards,

    Edvin

  • Hi  

    yes, this really resolves the timeout issue, no error happens again.

    but the connection between APP and BLE device can still not be established, when directed advertising.

    shall we on APP side change something? 

    Best regards

    Danny

  • Hi  

    I tested also advertise with white list, it's working.

    but I think what I want is directed advertising, so that the device is unvisible to other smartphones.

  • Check out Lesson 5 Exercise 2 in the Bluetooth Low Energy Fundamentals course on DevAcademy:

    https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/lessons/lesson-5-bluetooth-le-security-fundamentals/topic/blefund-lesson-5-exercise-2/

    If you add the filter accept list implemented there, it will only be possible to connect to it if you are on the list.

    I don't recall at the moment what makes the advertisements "invisible" from other devices. I can look into it next week. But note that it is not in fact invisible. Every scanner can see it, but if it sees some flag (directed advertising flag), and it is not bonded with the peripheral sending those advertisements, then it will ignore these advertisements (But you could still see it using e.g. nRF Connect for Android/iOS).

    Best regards,

    Edvin

  • Hi  

    Yes, that's the example I'm testing. 

    I just checked the iOS development guide, directed adverstisement is in any case not supported.
    So I think adverstisement with white list will be the general solution I can approach.

    We can close this thread, thanks a lot!

    Best regards,

    Danny

Reply Children
No Data
Related