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
  • Hi Zhang, 

     

    You would need to provide us more information on:

    - How you tested, have you made sure you erase bond and turn on and off iPhone Bluetooth before you tested (to clear any ATT table cache on the phone) , also make sure you enable service changed characteristic so that the phone would do service discovery when connected. 

    - Have you tried to use nRFConnect to connect and verify the attribute table is correct (with CTS service)

    - Let us know the SDK version, softdevice version. What exactly you do to add CTS into ANCS example ?

  • thank you. i test the CTS with my iphone. it's fine when only the CTS or ANCS service. but it's error when ANCS and CTS is together. I have read the code some times i can't find the bug. so its like the softdevice problem. can you give me a demo project for ANCS and CTS is together. the sdk version is 14.20. softdevice is S132.

  • Unfortunately, it's a pretty busy period we have now we can't provide you the example at the moment.

    What I would suggest you is to start again with the ANCS and try to add CTS in and let us know what goes wrong. I assume you want to implement CTS client ? 

Reply Children
Related