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

How to add the descriptions of GATT Primary Service(0x2800) and GATT characteristic?

How to add the descriptions of GATT Primary Service(0x2800) and GATT characteristic? Just like the picture below. image description

Parents
  • Hi

    You can use sd_ble_gatts_descriptor_add() to add Characteristic User Descriptions to your characteristics.

    You can do something like this:

    static uint32_t our_descriptor_add(ble_os_t * p_our_service, uint16_t char_handle)
    {
        uint32_t   err_code; // Variable to hold return codes from library and softdevice functions
        
        ble_gatts_attr_md_t    attr_md;
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 0;
        
        ble_uuid_t          attr_uuid;
        attr_uuid.uuid      = BLE_UUID_DESCRIPTOR_CHAR_USER_DESC;
        ble_uuid128_t       base_uuid = {0x23, 0xD1, 0x13, 0xEF, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}; // 128-bit base UUID
        err_code = sd_ble_uuid_vs_add(&base_uuid, &attr_uuid.type);
        APP_ERROR_CHECK(err_code); 
        
        
        uint8_t attr_value[]  = "Your User description";
        const uint16_t attr_len   = sizeof(attr_value);
        
        ble_gatts_attr_t    attr;
        memset(&attr, 0, sizeof(attr));
        
        attr.init_len       = attr_len;
        attr.max_len        = attr_len;
        attr.init_offs      = 0;
        attr.p_value        = attr_value;
        attr.p_attr_md      = &attr_md;
        attr.p_uuid         = &attr_uuid;
        
        err_code = sd_ble_gatts_descriptor_add(char_handle, &attr, &p_our_service->descr_handle);
        APP_ERROR_CHECK(err_code); 
        
        return err_code;
    }
    

    Please have a look at e.g. the ble_app_hids_mouse example in e.g. SDK 9.0.0. It shows how to add descriptors like this.

Reply
  • Hi

    You can use sd_ble_gatts_descriptor_add() to add Characteristic User Descriptions to your characteristics.

    You can do something like this:

    static uint32_t our_descriptor_add(ble_os_t * p_our_service, uint16_t char_handle)
    {
        uint32_t   err_code; // Variable to hold return codes from library and softdevice functions
        
        ble_gatts_attr_md_t    attr_md;
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 0;
        
        ble_uuid_t          attr_uuid;
        attr_uuid.uuid      = BLE_UUID_DESCRIPTOR_CHAR_USER_DESC;
        ble_uuid128_t       base_uuid = {0x23, 0xD1, 0x13, 0xEF, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}; // 128-bit base UUID
        err_code = sd_ble_uuid_vs_add(&base_uuid, &attr_uuid.type);
        APP_ERROR_CHECK(err_code); 
        
        
        uint8_t attr_value[]  = "Your User description";
        const uint16_t attr_len   = sizeof(attr_value);
        
        ble_gatts_attr_t    attr;
        memset(&attr, 0, sizeof(attr));
        
        attr.init_len       = attr_len;
        attr.max_len        = attr_len;
        attr.init_offs      = 0;
        attr.p_value        = attr_value;
        attr.p_attr_md      = &attr_md;
        attr.p_uuid         = &attr_uuid;
        
        err_code = sd_ble_gatts_descriptor_add(char_handle, &attr, &p_our_service->descr_handle);
        APP_ERROR_CHECK(err_code); 
        
        return err_code;
    }
    

    Please have a look at e.g. the ble_app_hids_mouse example in e.g. SDK 9.0.0. It shows how to add descriptors like this.

Children
Related