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

No ble events after DM_EVT_CONNECTION event. Am I doing some mistake in handling DM_EVT_CONNECTION ?

I am trying to run BLE central peripheral dual role on nrf52 pca10040 with nrf_uart as service. Also, I have redbearlab BLE nano as peripheral (nrf51822 based).

I am getting device manager's DM_EVT_CONNECTION event but after that I don't receive any event's or data. here is my DM_EVT_CONNECTION handler code :

printf("inside device manager event handler with event %x \n\r", p_event->event_id); 
switch (p_event->event_id)
{
    case DM_EVT_CONNECTION:
    {
        APPL_LOG("[APPL]: >> DM_EVT_CONNECTION\r\n");

        ble_gap_addr_t * peer_addr;
        peer_addr = &p_event->event_param.p_gap_param->params.connected.peer_addr;
        APPL_LOG("[APPL]:[%02X %02X %02X %02X %02X %02X]: Connection Established\r\n",
                            peer_addr->addr[0], peer_addr->addr[1], peer_addr->addr[2],
                            peer_addr->addr[3], peer_addr->addr[4], peer_addr->addr[5]);

        LEDS_OFF(CENTRAL_CONNECTED_LED);

        if(memcmp(&m_nus_peripheral_address, &p_event->event_param.p_gap_param->params.connected.peer_addr, sizeof(ble_gap_addr_t)) == 0)
        {
            m_conn_handle_central_nus = p_event->event_param.p_gap_param->conn_handle;
							printf("BLE connection handle valid \n\r"); 
        }
        if((m_conn_handle_central_nus != BLE_CONN_HANDLE_INVALID))
        {
            LEDS_OFF(CENTRAL_SCANNING_LED);
							printf("BLE connection handle invalid \n\r"); 
        }
              
        m_dm_device_handle = (*p_handle);

        // Discover peer's services. 
        err_code = ble_db_discovery_start(&m_ble_db_discovery,
                                          p_event->event_param.p_gap_param->conn_handle);
        APP_ERROR_CHECK(err_code);

        m_peer_count++;
					err_code = dm_security_setup_req(&m_dm_device_handle);
        APP_ERROR_CHECK(err_code);
					printf("[APPL]: << DM_EVT_CONNECTION done with service discovery error code %x \r\n",err_code );
        APPL_LOG("[APPL]: << DM_EVT_CONNECTION\r\n");
        break;
    }

The log is here :

BLE event 20002924
field type is 1, field length is 2
field type is 7, field length is 11
Decoded UUID is 1 and UUID type is 2
 Central Connected !! Connecting to target 0e79b2e74ad3
 BLE event 20002924
inside device manager event handler with event 11
[APPL]: >> DM_EVT_CONNECTION
[APPL]:[0E 79 B2 E7 4A D3]: Connection Established
[APPL]: << DM_EVT_CONNECTION done with service discovery error code 0
[APPL]: << DM_EVT_CONNECTION

Is there something missing ? Central device suppose to receive DM_EVT_SECURITY_SETUP event but it is not happening. Is there anything wrong at peripheral side ?

  • So if I understand you correctly the log above is when operating in the peripheral role, this means you have implemented device_manager_peripheral.c in your application. After connecting with the central you want to do a database discovery of the GATT server on the central, and you want to send a security request to inform the central you want to encrypt the link.

    Typically you pipeline these two operations, so you first initiate and finish a database discovery (wait for BLE_DB_DISCOVERY_COMPLETE), and then request to encrypt the link, for instance if you receive an insufficent authentication when trying to write to a specific characteristic on the GATT server.

    I don't see any immediate problems to initiate both database discovery and encrypt the link at the same time as you do, but you should be aware that the scenario is a bit unusual, as typically the peripheral contain the GATT server, and the central is the GATT client.

    Some questions that might help us dig through this: *Do you have an app_error_fault_handler() that might trigger? *Is it the same if ble_db_discovery_start() is commented out? *Can you check you are using device_manager_peripheral.c? *Is my understanding correct?

Related