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 ? 

  • Hi

    You should be able to get a warning of the connection status by implementing the QoS reports in your application, Please check out the Quality of Service library in NCS available here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/others/qos.html#quality-of-service. You should be able to make the application put out a warning if the quality goes below a set threshold.

    Best regards,

    Simon

  • 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 ?

  • Hi Gabriele

    Sorry, but what function are you referring to failing to send data here exactly? From the log, the error seems to come after the advertising fails to start and reporting that the devices are not connected, so I guess you first of all need to reconnect before trying to restart sending data between the devices.

    Best regards,

    Simon

  • Hi Simonr

    I think that advertising should restart before the central peer could re-connect. I want the device be able to restart the advertising regularly 

  • Gabriele said:
    I think that advertising should restart before the central peer could re-connect

    Yes, that's correct, but it seems like your application tries sending data instead of starting advertising. After a disconnect occurs I recommend you add a function that starts advertising again and quit the transmissions of data that should be done in a connection.

    Best regards,

    Simon

Related