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

Updating Service's Characteristic Value

So I have taken a starting point of adding multiple characteristics in the same service using this tutorial:

https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial

And the tutorial also shows how to update the value in the characteristic. But the problem is that the example has only one characteristic and it updates its value and as for me, I have multiple characteristic but cannot seem to find the option to update the 2nd or 3rd characteristic for example.

So I added the characteristics: 

    our_char_add_1(p_our_service);
    our_char_add_2(p_our_service);
    our_char_add_3(p_our_service);
    our_char_add_4(p_our_service);
    our_char_add_5(p_our_service);
    our_char_add_6(p_our_service);
    our_char_add_7(p_our_service);
    our_char_add_8(p_our_service);
    our_char_add_9(p_our_service);

and to update the function uses:

ble_os_t m_our_service;

our_temperature_characteristic_update(&m_our_service, &temperature);

void our_temperature_characteristic_update(ble_os_t *p_our_service, int32_t *temperature_value)
{
    // OUR_JOB: Step 3.E, Update characteristic value
    if (p_our_service->conn_handle != BLE_CONN_HANDLE_INVALID) //Here we check whether or not we are in a valid connection, and this is where the housekeeping comes in handy. If you try to send out notifications when not in a connection the SoftDevice will get grumpy and give you errors.
    {
        uint16_t               len = 4;
        ble_gatts_hvx_params_t hvx_params;
        memset(&hvx_params, 0, sizeof(hvx_params));
        
        //hvx stands for Handle Value X
        hvx_params.handle = p_our_service->char_handles.value_handle; //handle: The SoftDevice needs to know what characteristic value we are working on. In applications with two or more characteristics naturally we will need to reference the handle of the specific characteristic value we want to use. Our example only has one characteristic and we will use the handle stored in p_our_service->char_handles.value_handle.
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;  //type: The SoftDevice needs to know what "hvx type" we want to do; a notification or indication. As we are doing a notification we use BLE_GATT_HVX_NOTIFICATION. The other option would be BLE_GATT_HVX_INDICATION.
        hvx_params.offset = 0;  //offset: Your characteristic value might be a sequence of many bytes. If you want to transmit only a couple of these bytes and the bytes are located in the middle of the sequence you can use the offset to extract them. Since we want to update all of our four bytes we will set the offset to zero.
        hvx_params.p_len  = &len; //p_len: The SoftDevice needs to know how many bytes to transmit. There is no need to send 20 bytes every time if you only have four bytes of relevant data. As an example, let's say you have a characteristic with the following sequence of bytes: 0x01, 0x02, 0x03, 0x04, 0x05 and you want to send just the 3rd and the 4th byte. Then set offset to 2 and len to 2.
        hvx_params.p_data = (uint8_t*)temperature_value;    //p_data: Here we add a pointer to the actual data.
        



        sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params); //Running the parameters changed

    }


}

How can I jump to changing another characteristic value in the same service.

Any further questions for clarity should be asked without hesitation!

Parents Reply Children
No Data
Related