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

Distinguish, which of the Services triggered the BLE event "Notification enabled"

Hi all,

I am using SDK for mesh v. 3.1.0 next to SDK 15.2, nRF52832 DK. I have two services, NUS and Mesh Proxy Service. For both of the services there is registered a BLE observer. When the Notification in the NUS Service for TX Characteristic is enabled in the nRF Connect app, then it occurs BLE_GATTS_EVT_WRITE event on the side of GATT server. Snippet of code  below regarding the NUS Service event handler shows the event and checking if Notification enabled:

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;
    ble_nus_t * p_nus = (ble_nus_t *)p_context;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GATTS_EVT_WRITE:
            if((p_ble_evt->evt.gatts_evt.params.write.handle == p_nus->tx_handles.cccd_handle) &&
                    p_ble_evt->evt.gatts_evt.params.write.len == 2)
            {
                if (ble_srv_is_notification_enabled(p_ble_evt->evt.gatts_evt.params.write.data))
                {
                    p_client->is_notification_enabled = true;
                    SEGGER_RTT_printf(0, "%s(): Notification has been enabled\n", __func__);
                }
                else{
                     SEGGER_RTT_printf(0, "%s(): Notification has been disabled\n", __func__);
                }
            }
            break
    }
}

But the same event also occurs when configuring the node using Mesh Proxy Service. I want to send some data to nRF Connect app when the Notification is enabled, but using NUS service, not Mesh Proxy Service. But how to distinguish which of the Services enabled Notification ???

Parents
  • Could you please give me some hint? It is easy to distinquish which characteristic triggered the BLE event using:

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
        ble_nus_t * p_nus = (ble_nus_t *)p_context;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GATTS_EVT_WRITE:
            {
                if(p_ble_evt->evt.gatts_evt.params.write.uuid.uuid == 0x0002)
                {
                    //0x0002 is UUID for NUS UART characteristic, so fine it is 
                    //filtered
                    
                    ....some action....
                }break;
        }
    }

    But in the case of writing to CCCD descriptor, which has the SIG defined UUID = 0x2902, I dont know how to filter from which service was enabled notification.

Reply
  • Could you please give me some hint? It is easy to distinquish which characteristic triggered the BLE event using:

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
        ble_nus_t * p_nus = (ble_nus_t *)p_context;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GATTS_EVT_WRITE:
            {
                if(p_ble_evt->evt.gatts_evt.params.write.uuid.uuid == 0x0002)
                {
                    //0x0002 is UUID for NUS UART characteristic, so fine it is 
                    //filtered
                    
                    ....some action....
                }break;
        }
    }

    But in the case of writing to CCCD descriptor, which has the SIG defined UUID = 0x2902, I dont know how to filter from which service was enabled notification.

Children
No Data
Related