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

Will the softdevice (s110) inform the application when a characteristic is read?

I am running a GATT server with multiple proprietary characteristics. I need to perform an action when some of these characteristics are read. They are read-only characteristics.

I am tempted to use BLE_GATTC_EVT_READ_RSP in my on_ble_evt handler, but something tells me that will only fire if my gatt server were to request information.

Desired operation:

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t                         err_code = NRF_SUCCESS;
    static ble_gap_evt_auth_status_t m_auth_status;
    ble_gap_enc_info_t *             p_enc_info;
    
    switch (p_ble_evt->header.evt_id)
    {
			case <CLIENT (PHONE) READ A CHARACTERISTIC>: 
				{ filter on attribute handle/value and perform action }
				break;
    }
}
Parents
  • Hi there,

    The SoftDevice will only inform you of a read operation if you have set the rd_auth bit in ble_gatts_attr_md_t while populating the corresponding attribute (characteristic or descriptor). Otherwise the read operation will be handled and responded to autonomously by the SD without the application ever finding out.

    So make sure to set that bit whenever you call sd_ble_gatts_characteristic_add() for your proprietary chars and then you will get BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST every time the chars are read by the peer. You will then need to authorize the read operation (or deny it) by using sd_ble_gatts_rw_authorize_reply().

    See this MSC here for more details on authorization:

    devzone.nordicsemi.com/.../a00876.html

    Regards,

    Carles

  • Thank you, everything works now. For reference to readers - to authorize a read it is as simple as setting reply_params.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;. This was not immediately clear in the documentation.

Reply Children
No Data
Related