nRF5340 - peripheral disconnection because out of range

Hi,
I'm working on nRF5340 Bluetooth LE peripheral (building environment: NCS 2.6.1, Zephyr 3.5.99).
The net core is populated with the Zephyr HCI RPMsg sample LE Controller as it is.
I experience a disconnection from peer with reason BT_HCI_ERR_CONN_TIMEOUT.
This occurs because the peer is moved out of range.

How to get the application notified in advance of this disconnection event ? 

Parents Reply Children
  • Hi,
    this way seems a bit overkilling.
    My goal is to ensure the BLE data transmission from peripheral to central restarts seamlessly upon reconnection.
    The data transmit function I use is defined in module cp.c like this

    int bt_cp_send(struct bt_conn *conn, uint8_t *data, uint16_t len)
    {
      int ret;
      struct bt_gatt_notify_params params = {0};
      const struct bt_gatt_attr *attr = &css_svc.attrs[7];
    
      params.attr = attr;
      params.data = data;
      params.len = len;
      params.func = on_sent_cp;
    
      if (!conn) {
        ret = bt_gatt_notify_cb(NULL, &params);
      } else if (bt_gatt_is_subscribed(conn, attr, BT_GATT_CCC_NOTIFY)) {
        ret = bt_gatt_notify_cb(conn, &params);
      } else {
        return -EINVAL;
      }
    
      return ret;
    }

    Right after a disconnection event due to out of range condition, the function returns -128.
    I get on the console

    [00:01:22.337,493] <inf> bas: BAS Notifications disabled
    [00:01:22.343,231] <inf> cp: BT CP notify is DISABLED
    [00:01:22.349,578] <wrn> ble: disconnected from peer 00:E0:4C:32:98:9B (public) [reason: 0x08]
    [00[00:01:22.373,229] <err> ble: advertising failed to start [-12]
    :01:22.371,948] <wrn> bt_att: Not connected
    [00:01:22.387,847] <err> cp: BT CP failed to send data [-128]

    At 4th line something gets broken, preventing the advertising to restart clean.
    I need to restart advertising to allow a reconnection when the peers get back in range.
    Is there a specific action to take upon disconnection in order to avoid this situation ?

Related