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)
Related