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.

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

  • HI, I find a new bug on your project. when I connect the iphone and the ancs and cts was found, the connection will be break per 30s. I can't fix the bug, can you help me?

  • Hi, 

    It was a known issue. Please follow this answer from my colleague: 

    It has taken some time to dig into this. The relevant change between SDK 14.2.0 and 15.0.0 is that the ANCS example now subscribes to the service changed characteristic (and perform a service discovery when there is an indication on it). However, the example does not store the GATT database so that it can be reused between connections. Therefor the example also does a service discovery upon every reconnect. This is not the intended use of the service changed characteristic, and it seems that iOS will disconnect in this case, where the peer subscribes to the service changed characteristic but still does service discovery without an indication.

    There are several possible ways to fix this issue:

    1. The simplest is to comment out the call to nrf_ble_gatts_c_init() in main.c of the ANCS example. This will give it the same behavior as in SDK 14.2, where service changed is not subscribed to.
    2. Properly handle service changed indication, storing the database between connections. You can see how this is implemented in the GATT Service Client Example Application and use that as a reference if you want to implement this for ANCS.
  • thank you for your help. now I facing other question, if I "forget this device " on iphone then connect the buletooth , I get a PM_EVT_CONN_SEC_FAILED error. so I call to pm_peers_delete() then I get another error NRF_ERROR_CONN_COUNT,  can you give me some suggestion?

  • Hi, 

    If you set allow_repairing = False, the device will throw PM_EVT_CONN_SEC_FAILED if the phone lose bond information. 

    Set it to true, will allow repairing, but you have  the risk of attacker can spoof that it has lost bond information and re-pair to you. 

    Are you sure pm_peers_delete() throwing NRF_ERROR_CONN_COUNT ? Could you step into the code and check which function threw that and why ? 

Reply
  • Hi, 

    If you set allow_repairing = False, the device will throw PM_EVT_CONN_SEC_FAILED if the phone lose bond information. 

    Set it to true, will allow repairing, but you have  the risk of attacker can spoof that it has lost bond information and re-pair to you. 

    Are you sure pm_peers_delete() throwing NRF_ERROR_CONN_COUNT ? Could you step into the code and check which function threw that and why ? 

Children
No Data
Related