Topics

bt_gatt_notify multiple characteristics - always notification for the first characteristic #ble

frv
 

Hi all,

I have a user defined BT GATT service with 2 user defined characteristics.
The code is as simple as this for defining the GATT service.

static struct bt_uuid_128 uuidButtonService = BT_UUID_INIT_128(
        0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
        0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00);
 
static struct bt_uuid_128 uuidButtonStateCallStart = BT_UUID_INIT_128(
        0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
        0x00, 0x02, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00);
 
static struct bt_uuid_128 uuidButtonStateCallStop = BT_UUID_INIT_128(
        0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
        0x00, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00);
 
BT_GATT_SERVICE_DEFINE(button_svc,
        BT_GATT_PRIMARY_SERVICE(&uuidButtonService),
        BT_GATT_CHARACTERISTIC(&uuidButtonStateCallStart, BT_GATT_CHRC_NOTIFY,
                               BT_GATT_PERM_NONE, NULL, NULL, NULL),
        BT_GATT_CCC(buttonstate_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
        BT_GATT_CHARACTERISTIC(&uuidButtonStateCallStop, BT_GATT_CHRC_NOTIFY,
                               BT_GATT_PERM_NONE, NULL, NULL, NULL),
        BT_GATT_CCC(buttonstate_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)
);
 
void button_notify(bool value, uint8_t buttonNbr)
{
   printk("Button nbr %u - Notify value = %u\n", buttonNbr, value);
   onOffFlag = value;
 
   uint8_t index = 1;
   if (buttonNbr == 0)
   {
       index = 1;
   }
   else
   {
       index = 2;
   }
 
   printk("--->index is %u\n", index);
 
   bt_gatt_notify(NULL, &button_svc.attrs[index], &onOffFlag, sizeof(onOffFlag));
}

Nevertheless always the notification change of the first characteristic in the user defined service is trapped in the BT central application, despite the index value in button_svc.attrs changes between 1 and 2.

I see in my central output that the service and its characteristics are well discovered.
uuid service : 00000001-0100-0200-8000-00805f9b34fb
uuid char1 : 00000002-0100-0200-8000-00805f9b34fb
uuid char2 : 00000003-0100-0200-8000-00805f9b34fb

Any idea's what I'm doing wrong?
Thanks, 

Best regards,
Frank 
 

frv
 
Edited

Hi all,

Solved...
It looks like when BT_GATT_CCC is set in the service MACRO define, it  takes not 1 but 2 indices to advance as also there is automatically a descriptor char added if you need to access the second attribute. 

Best regards,
Frank