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

Problem discovering own services, no BLE_DB_DISCOVERY_COMPLETE event

Hello all, 

I'm working with the nRF51 SoCs, with the s130 SoftDevice and SDK12.1.0

I have a BLE Nano from Red Bear Lab that has a nRF51822 doing adv and it expose my own service, when I write a key in one of its characteristics value it opens a door, this works fine when I do this from an Android phone with the nRFConnect app.

Now I am trying to do that without the phone, so I flashed a central code to another BLE Nano that when it receives some external stimulus it starts to scan, connect, discovery, write and finally disconnect from the peripheral device that opens the door.

Using uart for debug and printing a message each time the device go to the ble_evt_dispatch() like this:

static void ble_evt_dispatch(ble_evt_t * p_ble_evt) {
	printf("ble_evt_dispatch\t");
	printf("%x", (int)p_ble_evt->header.evt_id);
	printf("\r\n");
	ble_tnds_c_on_ble_evt(&m_ble_tnds_c, p_ble_evt);
	on_ble_evt(p_ble_evt);
	bsp_btn_ble_on_ble_evt(p_ble_evt);
	ble_db_discovery_on_ble_evt(&m_ble_db_discovery, p_ble_evt);
}

printing something like this:

It works well most of the time, but some times the central device start scanning, then it connects to the peripheral device, and for an unknown the next dispatch event is the BLE_GAP_EVT_DISCONNECTED, this means that for some reason it connects and then disconnects without discovering the peripheral services,

I also tried the solution to the issue explained in this question.

I was wondering if anyone could help me understand what's going on.  

thanks

Edited: second image fixed, changing the numbers from decimal to hexadecimal

Parents
  • Hello,

    As I don't have your central project,it is hard to say exactly what the issue is.

    I assume that you don't have any debug capabilities, but can you go into the ble_db_discovery_on_ble_evt, and try to print a string on each of the event cases, to see what sort of discovery events you get? I am also not sure what SDK you use, but in SDK12.3.0, which is the latest SDK supporting nRF51, try to do something like this:

    void ble_db_discovery_on_ble_evt(ble_db_discovery_t * const p_db_discovery,
                                     const ble_evt_t * const    p_ble_evt)
    {
        VERIFY_PARAM_NOT_NULL_VOID(p_db_discovery);
        VERIFY_PARAM_NOT_NULL_VOID(p_ble_evt);
        VERIFY_MODULE_INITIALIZED_VOID();
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
                on_primary_srv_discovery_rsp(p_db_discovery, &(p_ble_evt->evt.gattc_evt));
                printf("PRIM_SRVC");
                break;
    
            case BLE_GATTC_EVT_CHAR_DISC_RSP:
                on_characteristic_discovery_rsp(p_db_discovery, &(p_ble_evt->evt.gattc_evt));
                printf("CHAR_DISC");
                break;
    
            case BLE_GATTC_EVT_DESC_DISC_RSP:
                on_descriptor_discovery_rsp(p_db_discovery, &(p_ble_evt->evt.gattc_evt));
                printf("EVT_DESC");
                break;
    
            case BLE_GAP_EVT_DISCONNECTED:
                on_disconnected(p_db_discovery, &(p_ble_evt->evt.gap_evt));
                printf("DISC_DISCONNECTED");
                break;
    
            default:
                break;
        }
    }

    To see if any of these events trigger.

    What is the event ble_evt_dispatch 17?

    BLE_GAP_EVT_AUTH_KEY_REQUEST?

    Are you handling this event? I can't see it in the scenario when everything goes well in your first log.

     

    Do you have a development kit where you can actually debug?

     

    Best regards,

    Edvin

Reply
  • Hello,

    As I don't have your central project,it is hard to say exactly what the issue is.

    I assume that you don't have any debug capabilities, but can you go into the ble_db_discovery_on_ble_evt, and try to print a string on each of the event cases, to see what sort of discovery events you get? I am also not sure what SDK you use, but in SDK12.3.0, which is the latest SDK supporting nRF51, try to do something like this:

    void ble_db_discovery_on_ble_evt(ble_db_discovery_t * const p_db_discovery,
                                     const ble_evt_t * const    p_ble_evt)
    {
        VERIFY_PARAM_NOT_NULL_VOID(p_db_discovery);
        VERIFY_PARAM_NOT_NULL_VOID(p_ble_evt);
        VERIFY_MODULE_INITIALIZED_VOID();
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
                on_primary_srv_discovery_rsp(p_db_discovery, &(p_ble_evt->evt.gattc_evt));
                printf("PRIM_SRVC");
                break;
    
            case BLE_GATTC_EVT_CHAR_DISC_RSP:
                on_characteristic_discovery_rsp(p_db_discovery, &(p_ble_evt->evt.gattc_evt));
                printf("CHAR_DISC");
                break;
    
            case BLE_GATTC_EVT_DESC_DISC_RSP:
                on_descriptor_discovery_rsp(p_db_discovery, &(p_ble_evt->evt.gattc_evt));
                printf("EVT_DESC");
                break;
    
            case BLE_GAP_EVT_DISCONNECTED:
                on_disconnected(p_db_discovery, &(p_ble_evt->evt.gap_evt));
                printf("DISC_DISCONNECTED");
                break;
    
            default:
                break;
        }
    }

    To see if any of these events trigger.

    What is the event ble_evt_dispatch 17?

    BLE_GAP_EVT_AUTH_KEY_REQUEST?

    Are you handling this event? I can't see it in the scenario when everything goes well in your first log.

     

    Do you have a development kit where you can actually debug?

     

    Best regards,

    Edvin

Children
No Data
Related