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
  • this is the only place where i call sd_ble_gatts_sys_attr_set.

    I use pm in the way that it is initialized and i have a pm event handler in my application.

    The only pm message i receive (PM_EVT_PEER_DATA_UPDATE_SUCCEEDED) is when i enable/disable notifications from client side, but dont take any actions on it.

    Short background for this piece of code is that I need to allow the client to enable/disable notifications only if the client previously sent a message with the intention to alter notification state. So the client needs to do it in 2 steps. Step1 send a message wants to enable/disable notifications, step2 send enable/disable command. I want to ignore any step2 command if not validated by step1. Safety requirement. 

Reply
  • this is the only place where i call sd_ble_gatts_sys_attr_set.

    I use pm in the way that it is initialized and i have a pm event handler in my application.

    The only pm message i receive (PM_EVT_PEER_DATA_UPDATE_SUCCEEDED) is when i enable/disable notifications from client side, but dont take any actions on it.

    Short background for this piece of code is that I need to allow the client to enable/disable notifications only if the client previously sent a message with the intention to alter notification state. So the client needs to do it in 2 steps. Step1 send a message wants to enable/disable notifications, step2 send enable/disable command. I want to ignore any step2 command if not validated by step1. Safety requirement. 

Children
No Data
Related