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

Not able to receive handles of custom service characteristics in central device

I am working in nRF52840 chip with SDK 15.3.0 and softdevice s140. I am looking to automate third party BLE peripheral device, this device is designed to connect with smart phone and then smartphone is communicating with server through internet. I am looking to eliminate smartphone by replacing it with custom central and ESP8266 module. I am able to use the peripheral through nRF Connect mobile app.

Now in code I am connected to device during db_discovery i am getting to the configured callback function but i am not getting characteristics of the peripheral. 

I am modifying ble_app_uart_c example from sdk. Please suggest the correct sample project which is using custom services to refer and modify according to my example.

Thanks.

  • I believe that the ble_app_uart_c is a good reference project to discover services and characteristics.

     

    Now in code I am connected to device during db_discovery i am getting to the configured callback function but i am not getting characteristics of the peripheral. 

     Is that the ble_nus_c_evt_handler with the evt_type = BLE_NUC_C_EVT_DISCOVERY_COMPLETE, or the ble_nus_c_on_db_disc_evt() in ble_nus_c.c? Or somewhere else?

    If it is the ble_nus_c_on_db_disc_evt(). Look at the unmodified implementation of ble_nus_c.c. What is the p_chars[i].characteristic.uuid.uuid? Is it the UUID that you expect? (Note that this callback may occur several times if the device has several services, so make sure you are checking the correct event, when p_evt->params.discovered_db.srv.uuid is the one that you expect.

    BR,
    Edvin

  • Hi Edvin 

    I was checking ble_nus_c_evt_handler for same function which you mentioned and i checked the pointer in watch window for all p_chars[], but all uuid were 0x00. 

    As my custom characteristic foot print is similar to nRF LBS service modified ble_app_blinky_c example to suit my needs and now it is working. How ever i am not sure what went wrong with ble_app_uart_c project modification.

    Thanks

  • Hello,

    Sorry for the late reply. I was out of office the last 14 days due to vacation.

    If you are still struggling with this:

    I don't know what your implementation looks like. If you look at the implementation from the ble_app_uart_c example:

    void ble_nus_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
    {
        ble_nus_c_evt_t nus_c_evt;
        memset(&nus_c_evt,0,sizeof(ble_nus_c_evt_t));
    
        ble_gatt_db_char_t * p_chars = p_evt->params.discovered_db.charateristics;
    
        // Check if the NUS was discovered.
        if (    (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE)
            &&  (p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE)
            &&  (p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type))
        {
            for (uint32_t i = 0; i < p_evt->params.discovered_db.char_count; i++)
            {
                switch (p_chars[i].characteristic.uuid.uuid)
                {
                    case BLE_UUID_NUS_RX_CHARACTERISTIC:
                        nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
                        break;
    
                    case BLE_UUID_NUS_TX_CHARACTERISTIC:
                        nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
                        nus_c_evt.handles.nus_tx_cccd_handle = p_chars[i].cccd_handle;
                        break;
    
                    default:
                        break;
                }
            }
            if (p_ble_nus_c->evt_handler != NULL)
            {
                nus_c_evt.conn_handle = p_evt->conn_handle;
                nus_c_evt.evt_type    = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
                p_ble_nus_c->evt_handler(p_ble_nus_c, &nus_c_evt);
            }
        }
    }

    You see that it checks a few things before it looks at the uuids:

    if ( (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE)
    && (p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE)
    && (p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type))

    Do you do the same check? Perhaps it is not a BLE_DB_DISCOVERY_COMPLETE event at all, in which case the uuids would not be populated.

    BR,

    Edvin

Related