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

BLE notification on nRF52833

Hi, 

I am trying to start from scratch BLE firmware to send and receive data from the development kit PCA10100 and nRFConnect App. I am following this course on Github here

I started with sending data and receiving data and that's all working for me so far. Now I'd like to notify the app that data changed and update the data value. In the Github course, the example supports enabling/disabling notification from the app. Therefore, the notification is handled in the 'write' event. I added this code into the write event:

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;
    
    // Custom Value Characteristic Written to.
    if (p_evt_write->handle == p_cus->custom_value_handles.value_handle)
    {
        nrf_gpio_pin_toggle(LED_4);
    }

    // Check if the Custom value CCCD is written to and that the value is the appropriate length, i.e 2 bytes.
    if ((p_evt_write->handle == p_cus->custom_value_handles.cccd_handle)
        && (p_evt_write->len == 2)
       )
    {
        // CCCD written, call application event handler
        if (p_cus->evt_handler != NULL)
        {
            ble_cus_evt_t evt;

            if (ble_srv_is_notification_enabled(p_evt_write->data))
            {
                evt.evt_type = BLE_CUS_EVT_NOTIFICATION_ENABLED;
            }
            else
            {
                evt.evt_type = BLE_CUS_EVT_NOTIFICATION_DISABLED;
            }
            // Call the application event handler.
            p_cus->evt_handler(p_cus, &evt);
        }
    }
}

The issue I have, the condition (ble_srv_is_notification_enabled(p_evt_write->data)) is never TRUE so I am not able to enable notification. I am displaying 'p_evt_write->data' on a terminal in hex and it is equal to this

Could you please support me on this? Why is p_evt_write->data = 2001FE56?

I wish to not use the enable condition from the App and update data when data value changes. How can I do that?

Many thanks

Related