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

Propagating BLE custom service events to main application

Hello,

I am trying to develop a custom BLE service. I have been following this tutorial

I have also looked at this answer to understand the signal path for a WRITE event.

"So the signal path for a BLE_GATTS_EVT_WRITE event which enables notification would be something like Softdevice event -> ble_evt_dispatch (in main)->ble_cus_on_ble_evt (in service)->on_write (in service)->on_cus_evt (in main)"

I seem to have a problem when I invoke the event handler in service to propagate to the main. When I Write a characteristic data on the nRF Connect app and send it, I get Error 133: GATT ERROR and then Error 8: GATT CONN TIMEOUT.

Here is the code snippet of on_write function in service.

static void on_write(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
    
    // Check if the handle passed with the event matches the Custom Value Characteristic handle.
    if (p_evt_write->handle == p_cus->custom_value_handles.value_handle) 
    {
        nrf_gpio_pin_toggle(LED_4);
        ble_cus_evt_t evt;
        evt.evt_type                  = BLE_CUS_EVT_WRITE;
         p_cus->evt_handler(p_cus, &evt,p_ble_evt);
    }
}

 

/**@brief Custom Service event handler type. */
typedef void (*ble_cus_evt_handler_t) (ble_cus_t * p_cus, ble_cus_evt_t * p_evt, ble_evt_t const * p_ble_evt);

Please help me understand what might be going wrong.

Thanks

Related