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

How to send data from multiple characteristics to the central ?

Hello everybody !

My code is based on the code of the "ble_app_template" to which I added my own custom service composed of 4 characteristics sending notifications. Notifications are sent to the central with a code based on "ble_app_multilink".

I want each characteristic to send its 8-byte notification to the panel and that it will display them.

uint32_t ble_cus_custom_value_update(ble_cus_t * p_cus, uint64_t custom_value, uint64_t custom_value2, uint64_t custom_value3, uint64_t custom_value4)
{
    NRF_LOG_INFO("In ble_cus_custom_value_update. \r\n"); 
    if (p_cus == NULL)
    {
        return NRF_ERROR_NULL;
    }

    uint32_t err_code = NRF_SUCCESS;
    ble_gatts_value_t gatts_value;

////////////////////////////////////////////////////////////////////////////////////////
//                                SENSOR n°1                                      //
////////////////////////////////////////////////////////////////////////////////////////

    // Initialize value struct.
    memset(&gatts_value, 0, sizeof(gatts_value));

    gatts_value.len     = sizeof(uint64_t);
    gatts_value.offset  = 0;
    gatts_value.p_value = &custom_value;

    // Update database.
    err_code = sd_ble_gatts_value_set(p_cus->conn_handle,
                                      p_cus->custom_value_handles.value_handle,
                                      &gatts_value);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Send value if connected and notifying.
    if ((p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)) 
    {
        ble_gatts_hvx_params_t hvx_params;

        memset(&hvx_params, 0, sizeof(hvx_params));

        hvx_params.handle = p_cus->custom_value_handles.value_handle;
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset = gatts_value.offset;
        hvx_params.p_len  = &gatts_value.len;
        hvx_params.p_data = gatts_value.p_value;

        err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
        NRF_LOG_INFO("sd_ble_gatts_hvx result: %x. \r\n", err_code); 
    }
}

So here's the problem:
Currently I send data that is incremented 4 features on my smartphone, so when it comes to sending data is good. Now, I would like to be able to recover this value on my central... but how ?

Thank you in advance for your assistance !
Related