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

ANCS can't receive the event when add CTS service to project.

Can anyone help me?

Each service is working standalone.

There are two cases:

1.the BLE can't connect auto by iphone.

2.firmware can't receive notify event.

static void services_init(void)
{
usr_ancs_services_init();
usr_cts_service_init();
}


void usr_ancs_services_init(void)
{
ble_ancs_c_init_t ancs_init_obj;
ret_code_t ret;

memset(&ancs_init_obj, 0, sizeof(ancs_init_obj));

ret = nrf_ble_ancs_c_attr_add(&m_ancs_c,
BLE_ANCS_NOTIF_ATTR_ID_APP_IDENTIFIER,
m_attr_appid,
ATTR_DATA_SIZE);
APP_ERROR_CHECK(ret);

ret = nrf_ble_ancs_c_attr_add(&m_ancs_c,
BLE_ANCS_NOTIF_ATTR_ID_TITLE,
m_attr_title,
ATTR_DATA_SIZE);
APP_ERROR_CHECK(ret);

ret = nrf_ble_ancs_c_attr_add(&m_ancs_c,
BLE_ANCS_NOTIF_ATTR_ID_MESSAGE_SIZE,
m_attr_message_size,
ATTR_DATA_SIZE);
APP_ERROR_CHECK(ret);

ret = nrf_ble_ancs_c_attr_add(&m_ancs_c,
BLE_ANCS_NOTIF_ATTR_ID_MESSAGE,
m_attr_message,
ATTR_DATA_SIZE);
APP_ERROR_CHECK(ret);

ancs_init_obj.evt_handler = on_ancs_c_evt;
ancs_init_obj.error_handler = apple_notification_error_handler;

usr_db_discovery_add_handler(usr_db_disc_handler);
APP_ERROR_CHECK(ble_ancs_c_init(&m_ancs_c, &ancs_init_obj));
}

void usr_cts_service_init(void)
{
ble_cts_c_init_t cts_init_obj;

cts_init_obj.evt_handler = on_cts_c_evt;
cts_init_obj.error_handler = current_time_error_handler;

usr_db_discovery_add_handler(db_disc_handler);
APP_ERROR_CHECK(ble_cts_c_init(&m_cts_c, &cts_init_obj));
}

#include "usr_db_discovery.h"
#include "ble_types.h"
#include "ble_srv_common.h"
#include "sdk_errors.h"
#include "ble_db_discovery.h"
#include "nrf_sdh_ble.h"
#include "app_error.h"
#include <string.h>

BLE_DB_DISCOVERY_DEF(m_db_disc);

static ble_db_discovery_evt_handler_t s_handler_list[5] = {0};
static uint16_t s_handler_list_length = 0;

static void usr_db_disc_handler(ble_db_discovery_evt_t * p_evt)
{
for (uint16_t i = 0; i < s_handler_list_length; i++) {
s_handler_list[i](p_evt);
}
}

uint32_t usr_db_discovery_start(uint16_t conn_handle)
{
APP_ERROR_CHECK(ble_db_discovery_start(&m_db_disc, conn_handle));
return NRF_SUCCESS;
}

void usr_db_discovery_init(void)
{
memset(&s_handler_list, 0, sizeof(s_handler_list));
s_handler_list_length = 0;

APP_ERROR_CHECK(ble_db_discovery_init(usr_db_disc_handler));
}

void usr_db_discovery_add_handler(ble_db_discovery_evt_handler_t h)
{
s_handler_list[s_handler_list_length] = h;
s_handler_list_length++;
}

Parents Reply
  • thank you, your project is OK, so i compare your code with me, I find you use the nrf_ble_gatts_c module. i don't clear why you add this, and i cann't add the module in my code because my project is base sdk 14.20, the module is different.  this is your code but put it to my project is error, because the sdk 14.20 can't find the "srv_changed_char",  do you have some suggest for me ?

Children
  • Hi Zhang, 

     

    The nrf_ble_gatts_c module added to handle gatt service and service changed characteristic. It handles the change in the attribute table of the peer device (the phone) . I'm not sure if it make the difference between your application and my application. 

    You can try to turn it off in my code to check if the application still works. I would suggest you to move to SDK v15 for your development. 

Related