I want to set more features in a single service, but once there are more than four features, some features will fail and no error will be reported. Some features in the service cannot be used. Why?
Below is my code to add services and features:
/**
@brief Register the application callback function. Call this function only once
@param pLwsProfile -[out] LWS Initialize the service structure
@param pAppCallback -[in] Callback to the application
@return NRF_SUCCESS - Success; other values-failure
*/
uint32_t LwsProfile_RegisterAppCallback(LwsProfile_t *pLwsProfile, const LwsProfileCallback_t *pAppCallback)
{
uint32_t errCode;
ble_uuid_t bleUuid;
ble_add_char_params_t addCharParams;
// Initialize the service structure
pLwsProfile->lWsProfileCharWriteHandler = pAppCallback->lWsProfileCharWriteHandler;
/*--------------------- service ---------------------*/
ble_uuid128_t baseUuid = {LWSPROFILE_UUID_BASE};
// Add base UUID
errCode = sd_ble_uuid_vs_add(&baseUuid, &pLwsProfile->uuidType);
VERIFY_SUCCESS(errCode);
//Add main service UUID
bleUuid.type = pLwsProfile->uuidType;
bleUuid.uuid = LWSPROFILE_UUID_SERVICE;
errCode = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
&bleUuid,
&pLwsProfile->serviceHandle);
VERIFY_SUCCESS(errCode);
/*--------------------- Feature 1--Update request---------------------*/
memset(&addCharParams, 0, sizeof(addCharParams));
addCharParams.uuid = LWSPROFILE_UUID_CHAR1;
addCharParams.uuid_type = pLwsProfile->uuidType;
addCharParams.init_len = sizeof(uint8_t);
addCharParams.max_len = LWSPROFILE_CHAR1_LEN; // Characteristic length
addCharParams.char_props.indicate = 1; // Declarable
addCharParams.cccd_write_access = SEC_MITM;
errCode = characteristic_add(pLwsProfile->serviceHandle, &addCharParams, &pLwsProfile->char1Handle);
if(errCode != NRF_SUCCESS)
{
return errCode;
}
/*--------------------- Feature 2 --Pressure---------------------*/
memset(&addCharParams, 0, sizeof(addCharParams));
addCharParams.uuid = LWSPROFILE_UUID_CHAR2;
addCharParams.uuid_type = pLwsProfile->uuidType;
addCharParams.init_len = sizeof(uint8_t);
addCharParams.max_len = LWSPROFILE_CHAR2_LEN; // Characteristic length
addCharParams.char_props.write = 1; // Writable
addCharParams.write_access = SEC_MITM;
errCode = characteristic_add(pLwsProfile->serviceHandle, &addCharParams, &pLwsProfile->char2Handle);
if(errCode != NRF_SUCCESS)
{
return errCode;
}
/*--------------------- Feature 3 --Temperature---------------------*/
memset(&addCharParams, 0, sizeof(addCharParams));
addCharParams.uuid = LWSPROFILE_UUID_CHAR3;
addCharParams.uuid_type = pLwsProfile->uuidType;
addCharParams.init_len = sizeof(uint8_t);
addCharParams.max_len = LWSPROFILE_CHAR3_LEN; // Characteristic length
addCharParams.char_props.write = 1; // Writable
addCharParams.write_access = SEC_MITM;
errCode = characteristic_add(pLwsProfile->serviceHandle, &addCharParams, &pLwsProfile->char3Handle);
if(errCode != NRF_SUCCESS)
{
return errCode;
}
/*--------------------- Feature 4 --Altitude ---------------------*/
memset(&addCharParams, 0, sizeof(addCharParams));
addCharParams.uuid = LWSPROFILE_UUID_CHAR4;
addCharParams.uuid_type = pLwsProfile->uuidType;
addCharParams.init_len = sizeof(uint8_t);
addCharParams.max_len = LWSPROFILE_CHAR4_LEN; // Characteristic length
addCharParams.char_props.write = 1; // Writable
addCharParams.write_access = SEC_MITM;
errCode = characteristic_add(pLwsProfile->serviceHandle, &addCharParams, &pLwsProfile->char4Handle);
if(errCode != NRF_SUCCESS)
{
return errCode;
}
/*--------------------- Feature 5 --Windspeed---------------------*/
memset(&addCharParams, 0, sizeof(addCharParams));
addCharParams.uuid = LWSPROFILE_UUID_CHAR5;
addCharParams.uuid_type = pLwsProfile->uuidType;
addCharParams.init_len = sizeof(uint8_t);
addCharParams.max_len = LWSPROFILE_CHAR5_LEN; // Characteristic length
addCharParams.char_props.write = 1; // Writable
addCharParams.write_access = SEC_MITM;
errCode = characteristic_add(pLwsProfile->serviceHandle, &addCharParams, &pLwsProfile->char2Handle);
if(errCode != NRF_SUCCESS)
{
return errCode;
}
/*--------------------- Feature 6 --Wind direction---------------------*/
memset(&addCharParams, 0, sizeof(addCharParams));
addCharParams.uuid = LWSPROFILE_UUID_CHAR6;
addCharParams.uuid_type = pLwsProfile->uuidType;
addCharParams.init_len = sizeof(uint8_t);
addCharParams.max_len = LWSPROFILE_CHAR6_LEN; // Characteristic length
addCharParams.char_props.write = 1; // Writable
addCharParams.write_access = SEC_MITM;
errCode = characteristic_add(pLwsProfile->serviceHandle, &addCharParams, &pLwsProfile->char3Handle);
if(errCode != NRF_SUCCESS)
{
return errCode;
}
/*--------------------- Feature 7 --Declination---------------------*/
memset(&addCharParams, 0, sizeof(addCharParams));
addCharParams.uuid = LWSPROFILE_UUID_CHAR7;
addCharParams.uuid_type = pLwsProfile->uuidType;
addCharParams.init_len = sizeof(uint8_t);
addCharParams.max_len = LWSPROFILE_CHAR7_LEN; // Characteristic length
addCharParams.char_props.write = 1; // Writable
addCharParams.write_access = SEC_MITM;
errCode = characteristic_add(pLwsProfile->serviceHandle, &addCharParams, &pLwsProfile->char4Handle);
if(errCode != NRF_SUCCESS)
{
return errCode;
}
return errCode;
}
Then I also followed other answers in the community, changing BLE_GATT_DB_MAX_CHARS to 16 was useless.
My feature processing function:
void LwsProfile_HandleCharValue(uint16_t connHandle, uint8_t charId, LwsProfile_t *pLwsProfile,
const uint8_t *pCharValue, uint16_t length)
{
switch(charId)
{
case LWSPROFILE_CHAR1:
NRF_LOG_INFO("LWS--ss1:%s", pCharValue);
LwsProfile_PushNotifyData(m_conn_handle, pLwsProfile, (uint8_t *)pCharValue, LWSPROFILE_CHAR1_LEN); // notify
break;
case LWSPROFILE_CHAR2:
NRF_LOG_INFO("LWS--ss2:%s", pCharValue);
break;
case LWSPROFILE_CHAR3:
NRF_LOG_INFO("LWS--ss3:%s", pCharValue);
LwsProfile_PushNotifyData(m_conn_handle, pLwsProfile, (uint8_t *)pCharValue, LWSPROFILE_CHAR3_LEN); // notify
break;
case LWSPROFILE_CHAR4:
NRF_LOG_INFO("LWS--ss4:%s", pCharValue);
break;
case LWSPROFILE_CHAR5:
NRF_LOG_INFO("LWS--ss5:%s", pCharValue);
break;
case LWSPROFILE_CHAR6:
NRF_LOG_INFO("LWS--ss6:%s", pCharValue);
LwsProfile_PushNotifyData(m_conn_handle, pLwsProfile, (uint8_t *)pCharValue, LWSPROFILE_CHAR6_LEN); // notify
break;
case LWSPROFILE_CHAR7:
NRF_LOG_INFO("LWS--ss7:%s", pCharValue);
break;
default:
break;
}
}
operation result:


Why are some of the features unavailable?
Use SDK17.02 and protocol stack s132
