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

Compare if received BLE data is equal to a specific value

Hi,

I successfully implemented a custom BLE service using this tutorial from Nordic. Also, thanks to a Nordic engineer, I have the QSPI example merged with the ble_app_template example with my custom BLE service. Now, I want to read the data received from that custom service and compare if the received data is equal to a specific value. If so, then I want to store it in the external Flash memory present in the NRF52840 DK using QSPI.

In my custom BLE service C file I use NRF_LOG_RAW_INFO inside the on_write function to see the data received via BLE:

/**
 * @brief Function for handling the Write event.
 *
 * @param[in]   p_cus       Custom Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_write(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
{
    const ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

    NRF_LOG_RAW_INFO("============================================================\n");
    NRF_LOG_RAW_INFO("                    RETRIEVED PARAMETERS                    \n");
    NRF_LOG_RAW_INFO("============================================================\n");

    uint16_t TOKEN    = (p_evt_write->data[1] << 8) + p_evt_write->data[0];

    NRF_LOG_RAW_INFO("TOKEN: %d\n", TOKEN);

    // 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);
    }

    // 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);
        }
    }
}

I want to know how can I access that data in the main.c file so I can compare if the data received via BLE is equal to a specific value. If so, I will use QSPI to store some data in the external Flash memory present in the NRF52840 DK.

Thanks in advance.

Parents
  • Hi,

    I want to know how can I access that data in the main.c file so I can compare if the data received via BLE is equal to a specific value. If so, I will use QSPI to store some data in the external Flash memory present in the NRF52840 DK.

     Essentially, the question as I understand it is: How can I get access in main.c to a variable that is set in a function in another source? You could use a global variable that you set in the callback handler in on_write(). 

    regards

    Jared 

Reply
  • Hi,

    I want to know how can I access that data in the main.c file so I can compare if the data received via BLE is equal to a specific value. If so, I will use QSPI to store some data in the external Flash memory present in the NRF52840 DK.

     Essentially, the question as I understand it is: How can I get access in main.c to a variable that is set in a function in another source? You could use a global variable that you set in the callback handler in on_write(). 

    regards

    Jared 

Children
Related