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

How to retrieve multiple values from a server with 1 services with several characteristics ?

Hello everybody !
Designing with the development board nRF52832 and SDK14.2.

My code is based on the code of the "ble_app_multilink_central" on which, I added some of the code "ble_app_uart_c" for the initialization and the event manager on the uart. I have a nrf52832 development board as a central and 2 nrf52832 developpement boards as a peripheral.

In a device, I created my personalized service composed of 4 characteristics.

My first question:
it's possible to send up to how many notifications at the same time to a single Client? Could I, in your opinion, send notifications with a size of 8 bytes? (I thought I saw that the max was 20 bytes so it's good).

Here is a simple diagram representing my system :

How to retrieve the value1, value2, value3 and value4 in the client?

Thank you in advance !

  • In fact, I know what it serves but I wanted to know what it interacts with the pheripheral code.

    It's true that I did not explain my project, it's my fault. So my project is to retrieve data from a sensor with the peripheral and store this data in its characteristics and after that, every 100ms (33ms objective) I send a notification to the central. As for a notification every second, I use the end of step 8 of this: https://github.com/bjornspockeli/custom_ble_service_example

    As far as my "notification_timeout_handler ()" is concerned, I have not yet set the values "m_custom_value = data_sensor" in my main () function, that's just an example of incrementing for my debugging

    This is the function ble_cus_custom_value_update () :

    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); 
        }
        else
        {
            err_code = NRF_ERROR_INVALID_STATE;
            NRF_LOG_INFO("sd_ble_gatts_hvx result: NRF_ERROR_INVALID_STATE. \r\n"); 
        }
    
    ////////////////////////////////////////////////////////////////////////////////////////
    //                                Sensor n°2                                      //
    ////////////////////////////////////////////////////////////////////////////////////////
    
    ...
    
    ////////////////////////////////////////////////////////////////////////////////////////
    //                                Sensor n°3                                      //
    ////////////////////////////////////////////////////////////////////////////////////////
    
    ...
    
    ////////////////////////////////////////////////////////////////////////////////////////
    //                                Sensor n°4                                      //
    ////////////////////////////////////////////////////////////////////////////////////////
    
    ...
    
        return err_code;
    }

    We can see that the function sd_ble_gatts_hvx () is there (line 45).

    In fact, I may have been poorly expressed, in terms of sending feature values to my smartphone, that's fine but it works for characteristics 2, 3 and 4 data only if I press the button that allows the notifications of the characteristicistic 1.

    Thanks again for the quality of the answer and the speed,

    Yoann_F

  • The button sets the CCCD to 0x01. 

    If I understand you correctly, this is working?

    I will follow up in your new case.

    If you want me to look at why the button for characteristics 2, 3 and 4 does not work, could you upload your project, so that I can test it?

     

    Best regards,

    Edvin

  • Ok thank you for this information.

    Yes almost I manage to do several notification at the same time there is just the problem that I specified just before: the characteristicistic 1 which launches the other characteristics.

    Oh ok super Slight smile

    if you want here is the project in zip :

    https://we.tl/6LFdLASFFj

    thanks again !

  • Hello,

    I have been out of office for a while, and have not had time to look at your project. Have you found out anything on why the enabling the notification on one of the characteristics enabled all? Or are you still stuck on this?

     

    Best regards,

    Edvin

Related