This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding Characteristic User Description 0x2901 before CCCD 0x2902

Hi, I'm trying to add Characteristic User Description 0x2901 and CCCD 0x2902 to a characteristic. It seems 0x2902 always comes before 0x2901 in attribute table. Is there any way to place 0x2901 before 0x2902?

Below is my code for adding 0x2901 and 0x2902. I'm currently using nRF52840 DK and SDK15.3.0. Thanks

    ble_gatts_char_md_t char_md;
    memset(&char_md, 0, sizeof(char_md));
    char_md.char_props.read = 1;
    char_md.char_props.write = 1;

    static char user_desc[] = "Reading";
    char_md.p_char_user_desc  = (uint8_t *) user_desc;
    char_md.char_user_desc_size = strlen(user_desc);
    char_md.char_user_desc_max_size = strlen(user_desc);
    
    ble_gatts_attr_md_t cccd_md;
    memset(&cccd_md, 0, sizeof(cccd_md));
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    cccd_md.vloc                = BLE_GATTS_VLOC_STACK;
    char_md.p_cccd_md           = &cccd_md;
    char_md.char_props.notify   = 1;

Parents
  • Hello,

    I actually don't know why it is placed in that order. Does it matter? Remember that the CCCD will always have UUID 2902, and Characteristic User Description will always have 2901. How do you read out the order of the attribute table? 

  • Hi Edvin,

    Thanks for your reply. I have a piece of utility code somebody else developed for me that takes CCCD handle as input. I could get notifications from different BLE sensors except for one that has 2901 before 2902. So before digging into the code, I would like to set up a quick test of swapping 2901 and 2902 orders in the same application and see if it's the cause.

  • Edvin said:
    How do you read out the order of the attribute table? 

     As I said, I don't know if these actually have a specific order. Perhaps the tool only looks for characteristic user descriptions before looking for CCCD?

    If it actually has an order, I don't know how you would change it. What does it look like in nRF Connect?

    Again, if there is an actual order of these, try changing how you initialize them. I don't know exactly what you would need to change.

  • Hello, order refers to handle number in attribute table. Please see attached picture. 

    For characteristic with handle 16, 2902 has handle 17 and 2901 has handle 18. I want to swap their order, so 2901 has handle 17 and 2902 has handle 18.

    Below is my code creating this characteristic, is there any place I could change their order in initialization? Thanks

    static uint32_t char_add_reading(ble_os_t * p_our_service)
    {
        uint32_t            err_code;
        ble_uuid_t          char_uuid;
        ble_uuid128_t       base_uuid = BLE_UUID_OUR_BASE_UUID;
        char_uuid.uuid      = BLE_UUID_READING_CHARACTERISTC_UUID;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
        APP_ERROR_CHECK(err_code);
    
        ble_gatts_char_md_t char_md;
        memset(&char_md, 0, sizeof(char_md));
        char_md.char_props.read = 1;
        char_md.char_props.write = 1;
    
        static char user_desc[] = "Reading";
        char_md.p_char_user_desc  = (uint8_t *) user_desc;
        char_md.char_user_desc_size = strlen(user_desc);
        char_md.char_user_desc_max_size = strlen(user_desc);
        
        ble_gatts_attr_md_t cccd_md;
        memset(&cccd_md, 0, sizeof(cccd_md));
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
        cccd_md.vloc                = BLE_GATTS_VLOC_STACK;
        char_md.p_cccd_md           = &cccd_md;
        char_md.char_props.notify   = 1;
       
        ble_gatts_attr_md_t attr_md;
        memset(&attr_md, 0, sizeof(attr_md));  
        attr_md.vloc        = BLE_GATTS_VLOC_STACK;
        
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
        ble_gatts_attr_t    attr_char_value;
        memset(&attr_char_value, 0, sizeof(attr_char_value));
        attr_char_value.p_uuid      = &char_uuid;
        attr_char_value.p_attr_md   = &attr_md;
    
        attr_char_value.max_len     = 4;
        attr_char_value.init_len    = 4;
        uint8_t value[4]            = {0x00,0x00,0x00,0x00};
        attr_char_value.p_value     = value;
    
        err_code = sd_ble_gatts_characteristic_add(p_our_service->service_handle,
                                                   &char_md,
                                                   &attr_char_value,
                                                   &p_our_service->char_handles_reading);
    
        return NRF_SUCCESS;
    }

  • The handles are just assigned in the order they are created. Since the CCCD is created first, it will be assigned first. This is done inside the softdevice, so it is not possible to change, unfortunately. 

    I have not seen this request before, but I guess it shouldn't be a problem. Why is it an issue that the CCCD handle has a lower handle value than the user description? Seeing as the handles are randomly assigned depending on how many services and characteristics you have, the natural approach would be to use the UUIDs that are fixed (according to the BLE specification). 

    BR,

    Edvin

  • Hi, as I mentioned there is a piece of utility code from somebody else that takes CCCD handle as input. I could get it working for all BLE sensors I have except for one that has 2901 before 2902. I am not sure if it really checks UUIDs when setting up notification, hence I wanted to do a quick test to swap 2901 and 2902 and see if it's the cause

Reply Children
No Data
Related