Device shows up in NrfConnect app as "non-connectable" despite he advertisement parameters being set to connectable.

Hey,

I am having an issue where my device doesn't show up in the Nrf Connect app as "connectable" despite as far as I can tell being set as a connectable device. This doesn't happen all the time but it happens most of the time. I wondered if this might be an issue with the Nrf Connect app somehow but when I upload the sample "central_and_peripheral_hr" it works fine. What's weirder is if I first upload "central_and_peripheral_hr" and then re-flash the device with my current code it shows up as connectable and I can confirm that my service shows up and I can send data to the device although it seems to still detect the Heart Rate service despite me not setting that up anywhere in my code as far as I can tell. Some relevant details is that I am using the distance measurement library and the device is simultaneously acting as a central device and is connected to a peripheral and is trading distance and random data with it. It is also communicating with a peripheral device with both the BAS and HR services. I am also using a custom service to communicate with the phone. I know the device isn't hitting an error at "bt_le_adv_start(). Relevant code below:

tatic const struct bt_data ad[] = {
    BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE,
        (CONFIG_BT_DEVICE_APPEARANCE >> 0) & 0xff,
        (CONFIG_BT_DEVICE_APPEARANCE >> 8) & 0xff),
    BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
    BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_PHN_VAL),

};

static const struct bt_data sd[] = {
    BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME)
};

static struct bt_le_adv_param *adv_param = BT_LE_ADV_PARAM(
    (BT_LE_ADV_OPT_CONNECTABLE |
     BT_LE_ADV_OPT_USE_IDENTITY), /* Connectable advertising and use identity address */
    800, /* Min Advertising Interval 500ms (800*0.625ms) */
    801, /* Max Advertising Interval 500.625ms (801*0.625ms) */
    NULL);
err = bt_le_adv_start(adv_param, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if (err) {
        printk("Advertising failed to start (err %d)\n", err);
        return;
    }

    printk("Advertising successfully started\n");
in a separate "peer.c" file.
static uint8_t phn_val = 0;
static uint8_t is_changed = 0;

static ssize_t print_data(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf,
             uint16_t len, uint16_t offset, uint8_t flags)
{
    //LOG_DBG("Attribute write, handle: %u, conn: %p", attr->handle, (void *)conn);

    if (len != 1U) {
        //LOG_DBG("Write led: Incorrect data length");
        return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
    }

    if (offset != 0) {
        //LOG_DBG("Write led: Incorrect data offset");
        return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
    }
    is_changed = 1;
    phn_val = *((uint8_t *)buf);
    printk("PHN DATA IS: %u\n", *((uint8_t *)buf));
    //printk("DATA IS: %d\n", ((uint8_t*)buf)[1]);
    return len;
}
In peer.h
#define BT_UUID_PHN_VAL 0x2bf6

#define BT_UUID_PHN \
    BT_UUID_DECLARE_16(BT_UUID_PHN_VAL)

#define BT_UUID_PHN_DAT_VAL 0x2bf7

#define BT_UUID_PHN_DAT \
    BT_UUID_DECLARE_16(BT_UUID_PHN_DAT_VAL)
Parents
  • Hello,

    This seems a bit strange. The advertiser should be connectable as long as the BT_LE_ADV_OPT_CONNECTABLE option flag is set. Could you provide a minimal version of your project that would allow me to reproduce the issue on an nRF5340 DK (I understand if this is too much work)? It may be a bug in the nRF Connect app, but I haven’t encountered this behavior before.

    Are you using nRF Connect on Android or iOS? Note that the phone is allowed to cache the services and characteristics from the previous connection so it does not have to repeat the service discovery on every connection. This may be an issue when re-program the FW on the device because it may still be using the same Bluetooth address and therefore continue to appear as the same device to the phone.

    Thanks,

    Vidar

  • Hey,

    Thanks for getting back to me. It might be at least partially the Nrf Connect app bc I downloaded BLE scanner 4.0 and was able to connect and send data to my device even while Nrf Connect was showing it at non-connectable. I don't understand why the central_peripheral_hr app would work perfectly with Nrf connect though if it is an issue on your end.  I am using the iOS version. I have not tried this with the Android version but I could. I could potentially send you some more of my code but I am not sure what is meant by "minimal version".

    EDIT: Code does work with the Andriod version of the Nrf Connect app.

  • Hi,

    Customer projects will often have external hardware dependencies, etc that prevent the code from being run on a development kit. So by "minimal," I meant a project without any additional dependencies that can easily be tested on a DK. Sorry for not being more clear on that. 

    After the connect button is not showing, have you tried closing the app, toggling Bluetooth off and on from Settings > Bluetooth (not from the control center), and then reopened the app again to see if the problem persists?

    I will ask our mobile apps team if this is something they have seen before.

Reply
  • Hi,

    Customer projects will often have external hardware dependencies, etc that prevent the code from being run on a development kit. So by "minimal," I meant a project without any additional dependencies that can easily be tested on a DK. Sorry for not being more clear on that. 

    After the connect button is not showing, have you tried closing the app, toggling Bluetooth off and on from Settings > Bluetooth (not from the control center), and then reopened the app again to see if the problem persists?

    I will ask our mobile apps team if this is something they have seen before.

Children
No Data
Related