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

not able to set system attributes using sd_ble_gatts_sys_attr_set

Hello

I'm trying to reenable notifications on a characteristic from GATTS side

The device is 52810 running a custom service and this is the piece of code where i use

 err_code = sd_ble_gatts_sys_attr_get(m_service.conn_handle, 0, &attr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS);
 err_code = sd_ble_gatts_sys_attr_get(m_service.conn_handle, sys_attr_data, &attr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS);
      
      for(uint8_t i = 0; i < attr_len; i+= 6)
        {
        if(sys_attr_data[i] == iterator->value_handles.cccd_handle && sys_attr_data[i + 4] == 0)
          {
          sys_attr_data[i + 4] = 1;
          crc = crc16_compute(sys_attr_data, attr_len - 2, NULL);
          sys_attr_data[attr_len - 2] = crc & 0xff;
          sys_attr_data[attr_len - 1] = crc >> 8;
          err_code = sd_ble_gatts_sys_attr_set(m_service.conn_handle, sys_attr_data, attr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS);    // initialize cccd attribute
          NRF_LOG_INFO("sys attr set: %2x / %2x %2x %2x", err_code, sys_attr_data[0], sys_attr_data[2], sys_attr_data[4]);
          memset(sys_attr_data, 0, 32);
          err_code = sd_ble_gatts_sys_attr_get(m_service.conn_handle, sys_attr_data, &attr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS);
          NRF_LOG_INFO("sys attr get: %2x / %2x %2x %2x", err_code, sys_attr_data[0], sys_attr_data[2], sys_attr_data[4]);
          break;
          }
        }

log output is like this

[00:00:49.204,101] <info> app: sys attr set: 0 / E 2 1
[00:00:49.204,162] <info> app: sys attr get: 0 / E 2 0

The value set is 1 and the value get is 0, return value for both calls ...set() and ...get() is NRF_SUCCESS

can someone suggest how to set the value?

Parents
  • Hi,

    Are you calling sd_ble_gatts_sys_attr_set() other places? 

    Only the first call to sd_ble_gatts_sys_attr_set() will have an effect. The second call does nothing and returns SUCCESS. sd_ble_gatts_sys_attr_set() is used to restore CCCD's on reconnection, if you are using the Peer Manger, then Peer Manger handles this for you. If you want to set other attributes, that are not system attributes, use sd_ble_gatts_value_set()

Reply
  • Hi,

    Are you calling sd_ble_gatts_sys_attr_set() other places? 

    Only the first call to sd_ble_gatts_sys_attr_set() will have an effect. The second call does nothing and returns SUCCESS. sd_ble_gatts_sys_attr_set() is used to restore CCCD's on reconnection, if you are using the Peer Manger, then Peer Manger handles this for you. If you want to set other attributes, that are not system attributes, use sd_ble_gatts_value_set()

Children
No Data
Related