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.

  • Yes, the phone has the CTS server but you still need the CTS client on the nRF52. 

    I'm not sure what caused the non-autoconnect. Please try to fix issue number 2 first. Regarding issue number 1, make sure when you advertise you advertise as ANCS device not CTS. 

  • I have tested the ANCS is fine, it can autoconnect. and have a notify when the iphone get a message. but it can't work if I add the CTS service to the ANCS project. I don't known the issue is where. I've read the code many times. i can't find the issue.Can you give me some new suggest ?

  • Hi Zhang, 

     

    Please try this example that I combined the 2 service. Let me know if you see any problem. 

    It's for SDK v15, nRF52832 , Keil v5.

    ble_app_ancs_c_cts_c.zip

  • 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 ?

  • 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. 

Reply
  • 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. 

Children
No Data