Can't send two separate BLE indications

Starting with the lbs example from lesson l4e2 of BT fundamentals course, I'd like to send an indication similar to the button (and keep the button). I basically created duplicates of everything related to the button and pointed it to different data. So I have:

BT_GATT_SERVICE_DEFINE
(
    my_lbs_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_LBS),
    BT_GATT_CHARACTERISTIC(BT_UUID_LBS_BUTTON, BT_GATT_CHRC_READ | BT_GATT_CHRC_INDICATE, BT_GATT_PERM_READ, read_button, NULL, &button_state),     
    BT_GATT_CCC(mylbsbc_ccc_cfg_changedButton, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),

    BT_GATT_CHARACTERISTIC(BT_UUID_LBS_KDR, BT_GATT_CHRC_READ | BT_GATT_CHRC_INDICATE, BT_GATT_PERM_READ, read_kdr, NULL, &kdr_state),
    BT_GATT_CCC(mylbsbc_ccc_cfg_changedKdr, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
)
and 
static ssize_t read_button(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
{
    const char *value = attr->user_data;
    if (lbs_cb.button_cb)
    {
        button_state = lbs_cb.button_cb();
        return bt_gatt_attr_read(conn, attr, buf, len, offset, value, sizeof(*value));
    }

    return 0;
}

static ssize_t read_kdr(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
{
   const char *value = attr->user_data;
    if (lbs_cb.kdr_cb)
    {
        kdr_state = lbs_cb.kdr_cb();
        return bt_gatt_attr_read(conn, attr, buf, len, offset, value, sizeof(*value));
    }

    return 0;
}
and
int my_lbs_send_button_state_indicate(bool button_state)
{
   
    if (!indicate_enabled)
    {
        return -EACCES;
    }
    ind_params.attr = &my_lbs_svc.attrs[2];             
    ind_params.func = indicate_cb;
    ind_params.destroy = NULL;
    ind_params.data = &button_state;
    ind_params.len = sizeof(button_state);
    return bt_gatt_indicate(NULL, &ind_params);
}

int my_lbs_send_kdr_state_indicate(bool kdr_state)
{
    if (!indicate_enabled)              
    {
        return -EACCES;
    }
    ind_params.attr = &my_lbs_svc.attrs[2];
    ind_params.func = indicate_cb;
    ind_params.destroy = NULL;
    ind_params.data = &kdr_state;
    ind_params.len = sizeof(kdr_state);
    return bt_gatt_indicate(NULL, &ind_params);
}
etc.
The problem is that in nRF Connect, the button_state characteristic displays my kdr_state, and the kdr_state characteristic doesn't display anything.
I suspect that the problem has to do with using the same parameters in both information chains, like how &my_lbs_svc.attrs[2] is used in both places. But that's just a guess due to my inability to understand all the helper macros.
Can you please point me in the right direction?
Parents
  • Hello,

    You were on the right track. The problem, as you pointed out, is that ind_params.attr must point to the correct attribute handle (the one matching the characteristic you are trying to send the indication from). &my_lbs_svc.attrs[2] points to the value handle for your BT_UUID_LBS_BUTTON characteristic, which is correct for my_lbs_send_button_state_indicate(), but this index needs to be updated in my_lbs_send_kdr_state_indicate(). 

    &my_lbs_svc.attrs[4] or &my_lbs_svc.attrs[5] should work for  my_lbs_send_kdr_state_indicate().

    int my_lbs_send_kdr_state_indicate(bool kdr_state)
    {
        if (!indicate_enabled)              
        {
            return -EACCES;
        }
        ind_params.attr = &my_lbs_svc.attrs[5];
        ind_params.func = indicate_cb;
        ind_params.destroy = NULL;
        ind_params.data = &kdr_state;
        ind_params.len = sizeof(kdr_state);
        return bt_gatt_indicate(NULL, &ind_params);
    }

    How you can find this index is explained in section 5.2 of the exercise your are working with. 

    Best regards,

    Vidar

Reply Children
No Data
Related