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

Avoid service discovery

I am using S130, SDK13 and NRF52832 both on my central and peripheral - custom boards.

I am trying to avoid service discovery on my peripheral. 

I have set the service_changed to 0 when configuring the softdevice.

On my central I do not run service-discovery, but my peripheral does not get a handle to the service even though I run this code when I connect:

void ble_lbs_status_update (ble_alarm_service_t* p_our_service, uint8_t *p_lock_state, uint16_t len) {

    uint32_t err_code = NRF_SUCCESS;

    ble_gatts_value_t gatts_value;

    // Initialize value struct.

    memset(&gatts_value, 0, sizeof(gatts_value));

    gatts_value.len     = sizeof(uint8_t)*len;

    gatts_value.offset  = 0;

    gatts_value.p_value = p_lock_state;

    // new

    // Update database.

    err_code = sd_ble_gatts_value_set (p_our_service->conn_handle, p_our_service->status_char_handles.value_handle, &gatts_value);

    if (err_code != NRF_SUCCESS)

    {

       return err_code;

    }

    //new

if (p_our_service->conn_handle != BLE_CONN_HANDLE_INVALID)

{

uint16_t               len = 5;

ble_gatts_hvx_params_t hvx_params;

memset(&hvx_params, 0, sizeof(hvx_params));

hvx_params.handle = p_our_service->status_char_handles.value_handle;

        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;

        hvx_params.offset = gatts_value.offset;

        hvx_params.p_len  = &gatts_value.len;

        hvx_params.p_data = gatts_value.p_value;

sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params);

}

}

Do you have a check-list of how to avoid service discovery on a peripheral?

Regards
Jens

  • Hi,

    I am slightly confused, is the gatt server on the peripheral or on the central? Regardless you should probably disable the Database Discovery Module if you do not want to do service discovery. But please note that you will have to hard code the attribute handles on the gatt client if you do not do service discovery.

  • Hi,

    it is the gatt server on the peripheral! 

    How do you hard code the attribute handle on the gatt client? The handle is a unint8 - do I set it to 0x0001?

  • sorry - uint16_t. But is it correct to hard code it with the value 0x0001. I only have one custom service.

  • The gatt server on the peripheral does not do service discovery. You can connect to you peripheral using nRF connect to check what attribute handle your custom characteristic has, it is not 0x0001.

    If you need additional information on how to set up the service and characteristics I would recommend that you take a look at our tutorial section here.

  • On the GATT server I have hard coded the handles:

    #define BLE_LOCK_STATUS_HANDLE     0x0014

    #define BLE_LOCK_STATUS_CCCD_HANDLE 0x0015

    #define BLE_LOCK_CMD_HANDLE         0x0017

    #define BLE_LOCK_NAME_HANDLE     0x0019

    #define BLE_LOCK_VERSION_HANDLE     0x001B

    Still does not work. What do I need to do on the client side to make it work?

1 2 3 4