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

Custom service with multiple peripheral links - notify all connections instead of last connected only

nRF52862, SDK 14.2, SD 5.1.0,, Arm GCC (Eclipse)

I have a custom service that is working well when 1 device (phone) is connected. All notifications are sent properly to the phone.

I used the multi peripheral example in  SDK 14.2 to allow multiple links (connections). I set NRF_SDH_BLE_PERIPHERAL_LINK_COUNT to 3 in sdk_config.h.

When I connect a second device (phone), it connects fine and works well but any notifications are only sent to the second device and not the first connected device. I am only getting notifications on one device at a time.

I assume that has something to do with my service only sending one update out for the one conn_handle.

See code below that shows my temperature characteristic update:

void our_temperature_characteristic_update(ble_os_t *p_our_service, uint8_t *temperature_value)
{
    if (p_our_service->conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        uint16_t               len = 1;
        ble_gatts_hvx_params_t hvx_params;
        memset(&hvx_params, 0, sizeof(hvx_params));
        hvx_params.handle = p_our_service->char_a_handles.value_handle;
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset = 0;
        hvx_params.p_len  = &len;
        hvx_params.p_data = (uint8_t*)temperature_value;
        sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params);
    }
}

What I would like it to do is send out that notification to every conn_handle that is connected.


Hopefully I explained this clearly enough.

Thanks in advance

Parents
  • Just as a follow-up in case someone else comes across this. I fixed the issue and everything is working great now with multiple connections..

    My characteristic update functions, now look similar to this:

    void our_temperature_characteristic_update(ble_os_t *p_our_service, uint8_t *temperature_value)
    {
        if (p_our_service->conn_handle != BLE_CONN_HANDLE_INVALID)
        {
        	sdk_mapped_flags_key_list_t conn_handles = ble_conn_state_periph_handles();
        	for (uint8_t i = 0; i < conn_handles.len; i++)
        	    {
    				uint16_t               len = 1;
    				ble_gatts_hvx_params_t hvx_params;
    				memset(&hvx_params, 0, sizeof(hvx_params));
    				hvx_params.handle = p_our_service->char_a_handles.value_handle;
    				hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
    				hvx_params.offset = 0;
    				hvx_params.p_len  = &len;
    				hvx_params.p_data = (uint8_t*)temperature_value;
    				sd_ble_gatts_hvx(conn_handles.flag_keys[i], &hvx_params);
        	    }
        }
    }

    Notice: sdk_mapped_flags_key_list_t conn_handles = ble_conn_state_periph_handles(); . I call that to get a list of connection handles and then send the update to each one of them. (Had to include sdk_mapped_flags.h and ble_conn_state.h )

    I also now only make

     

    p_our_service->conn_handle = BLE_CONN_HANDLE_INVALID

    when there are no connections.(Old code made it INVALID once any connection dropped).

    Hope this helps someone out.

Reply
  • Just as a follow-up in case someone else comes across this. I fixed the issue and everything is working great now with multiple connections..

    My characteristic update functions, now look similar to this:

    void our_temperature_characteristic_update(ble_os_t *p_our_service, uint8_t *temperature_value)
    {
        if (p_our_service->conn_handle != BLE_CONN_HANDLE_INVALID)
        {
        	sdk_mapped_flags_key_list_t conn_handles = ble_conn_state_periph_handles();
        	for (uint8_t i = 0; i < conn_handles.len; i++)
        	    {
    				uint16_t               len = 1;
    				ble_gatts_hvx_params_t hvx_params;
    				memset(&hvx_params, 0, sizeof(hvx_params));
    				hvx_params.handle = p_our_service->char_a_handles.value_handle;
    				hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
    				hvx_params.offset = 0;
    				hvx_params.p_len  = &len;
    				hvx_params.p_data = (uint8_t*)temperature_value;
    				sd_ble_gatts_hvx(conn_handles.flag_keys[i], &hvx_params);
        	    }
        }
    }

    Notice: sdk_mapped_flags_key_list_t conn_handles = ble_conn_state_periph_handles(); . I call that to get a list of connection handles and then send the update to each one of them. (Had to include sdk_mapped_flags.h and ble_conn_state.h )

    I also now only make

     

    p_our_service->conn_handle = BLE_CONN_HANDLE_INVALID

    when there are no connections.(Old code made it INVALID once any connection dropped).

    Hope this helps someone out.

Children
No Data
Related